Can You Substitute a Control Name With a Variable?
This code is a snippet from one of the modules in my program. It works perfectly, but I now need to do the exact same thing....but with another form. Is there a way I can substitute the "frmMain.lstDoctors" with a variable name so that I can pass this function the name of the control I'd like to use, when I'd like to use it?
VB Code:
With rsDoctorList
'Run Query & move to the first record...
.MoveFirst
Do While Not .EOF
If IsNumeric(.Fields!PhysicianNo) Then ' ensures the physician number is numeric and not alphanumeric
If .Fields!Active = "Y" Then
frmMain.lstDoctors.AddItem .Fields!Lastname & ", " & .Fields!FIRSTNAME
frmMain.lstDoctors.ItemData(frmMain.lstDoctors.NewIndex) = .Fields!PhysicianNo
.MoveNext
Else
.MoveNext
End If
Else
.MoveNext
End If
Loop
End With
'The visible property of the lstDoctors control is set to False by default. This loads the records a lot faster.
'We then have to display the control on the form.
frmMain.lstDoctors.Visible = True
Exit Sub
Re: Can You Substitute a Control Name With a Variable?
pass the control object:
VB Code:
Private Function MyFunction(ByRef oListBox As ListBox) As Boolean
Debug.Print oListBox.Name 'etc.
End Function
Private Sub Command1_Click()
MyFunction List1
End Sub