Results 1 to 4 of 4

Thread: Visual Basic for Applications

  1. #1

    Thread Starter
    Lively Member Rockman's Avatar
    Join Date
    Apr 2001
    Posts
    66

    Smile Visual Basic for Applications

    Any VBA experts out there that know the right syntax to pass a control as a parameter of a subroutine?

    For example:

    Code:
    Private Sub ChangeEnabled(Generic as Textbox)
       Generic.Enabled = not(Generic.Enabled)
    End Sub
    
    Private Sub Main
       Call ChangeEnabled(Me!myTextbox)   'This doesn't work
    End Sub
    Thanks for any help,
    Jeff

  2. #2
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273
    Private Sub Main
    Call ChangeEnabled(Me.myTextbox)
    End Sub

  3. #3
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    I don't know about VBA, but in VB you can declare a control as a generic control if you need to. For example, if you wanted to populate a list, you would want to be able to pass a listbox or a combobox:

    VB Code:
    1. Sub PopulateList (lst As Control)
    2.  
    3. If TypeName(ctl) <> "ListBox" And TypeName(ctl) <> "ComboBox" Then
    4.   Exit Sub
    5. End If
    6.  
    7. ' Do something with control here
    8.  
    9. End Sub

  4. #4

    Thread Starter
    Lively Member Rockman's Avatar
    Join Date
    Apr 2001
    Posts
    66
    Thanks for the responses.

    You are both right.

    My problem was that I had imported an MSFlexGrid and yet my subroutine would not accept:
    Code:
    Private Sub SetupFlex(myFlex as MSFlexGrid)
    I changed it to:
    Code:
    Private Sub SetupFlex(myFlex as control)
    and it works great now.

    Thanks for the help,
    Jeff

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