Results 1 to 2 of 2

Thread: Can You Substitute a Control Name With a Variable?

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    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:
    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

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Can You Substitute a Control Name With a Variable?

    pass the control object:
    VB Code:
    1. Private Function MyFunction(ByRef oListBox As ListBox) As Boolean
    2.     Debug.Print oListBox.Name 'etc.
    3. End Function
    4.  
    5. Private Sub Command1_Click()
    6.     MyFunction List1
    7. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width