When I refered to "Me.Controls" I assumed the "Me" refered to Form
containing the controls.  If so, then the Controls property returns a
ControlCollection that can be searched by control name as in the
example I sent earlier.

If your "Me.Controls" won't accept a String, then Me is not refering
to your form, and Controls is not returning a ControlCollection.

This is confirmed by the example which you say works.  frmInformation
is the form you are searching, and it in turn belongs to Me.  Which
begs the question about what Me really is.  Ignoring that, you can
reword my original example as follows and it will work now.

Private Sub BoldLabel(ByRef LabelName as String)
       frmInformation.Controls(LabelName).Font = New
System.Drawing.Font("Courier
New", 12.0!, FontStyle.Bold)
End  '  Bold Label

If you want to handle possible errors, such as an invalid LableName,
you could add a check before the Font assignment.  For example:
Private Sub BoldLabel(ByRef LabelName as String)
      If frmInformation.Controls.Contains(LabelName) then
          frmInformation.Controls(LabelName).Font = New
System.Drawing.Font("Courier
      End If
New", 12.0!, FontStyle.Bold)

Knowing the type, properties, and methods of your objects are key to
being able to accomplish anything in modern languages.  Learn to read
the help information and understand what it is telling you.  It can be
confusing, but it will make your tasks a lot easier to accomplish.

-- R.B. Davidson

On Feb 3, 12:37 am, VillageIdiot <[email protected]> wrote:
> This solution works.  Is there a better way though?
>
> Private Sub BoldLabel(ByRef LabelName as String)
>      Dim ControlName as Control
>
>     For Each ControlName in Me.frmInformation.Controls
>
>         If ControlName.Name = LabelName then
>            ' ...make the label bold...
>             Exit Sub
>         End If
>
>     Next  ' Next ControlName
>
> End Sub  ' Bold Label
>
> newbie
>
> P.S.
>    Thanks a lot R.B. for pointing me in the right direction  :)

Reply via email to