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:
  1. With rsDoctorList
  2.      'Run Query & move to the first record...
  3.       .MoveFirst
  4.          Do While Not .EOF
  5.             If IsNumeric(.Fields!PhysicianNo) Then ' ensures the physician number is numeric and not alphanumeric
  6.                If .Fields!Active = "Y" Then
  7.                   frmMain.lstDoctors.AddItem .Fields!Lastname & ", " & .Fields!FIRSTNAME
  8.                   frmMain.lstDoctors.ItemData(frmMain.lstDoctors.NewIndex) = .Fields!PhysicianNo
  9.                   .MoveNext
  10.                Else
  11.                   .MoveNext
  12.                End If
  13.             Else
  14.               .MoveNext
  15.             End If
  16.          Loop
  17.   End With
  18.  
  19. 'The visible property of the lstDoctors control is set to False by default. This loads the records a lot faster.
  20. 'We then have to display the control on the form.
  21.   frmMain.lstDoctors.Visible = True
  22.   Exit Sub