Results 1 to 2 of 2

Thread: Passing MSAccess 2000 objects to functions

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2003
    Location
    London
    Posts
    44

    Passing MSAccess 2000 objects to functions

    I have a problem, I am trying to pass a VBA control to a function, but I cannot seem to be able to do this. The control can be a Textbox, a Checkbox or a MSHFlexgrid, so I want a generic function that allows me to do this. Depending on the control, I can use SELECT CASE to handle it within the function.

    Passing the MSHFlexgrid and the Checkbox is easy, its the Textbox I am having problems with. You cannot call the Textbox by name because VBA assumes you are calling the Textbox.text field, and this causes a Type mismatch

    For example I have a Textbox called Text1, a MSHFlexGrid called Grid1 and a CheckBox called Check1.

    VB Code:
    1. Private Sub SaveData(ctrl as Control)
    2.     Select Case ctrl.ControlType
    3.     Case 119   'MSHFlexGrid
    4.         Dim g as MSHFlexGrid
    5.         Set g = ctrl.object
    6.         'Do Grid manipulation
    7.     Case 106   'Checkbox
    8.         Dim c as Checkbox
    9.         Set c = ctrl
    10.         'Do Checkbox manipulation
    11.     Case 109   'Textbox
    12.         Dim c as Textbox
    13.         Set c = ctrl
    14.         'Do Textbox manipulation
    15.     End Select
    16. End Sub
    17.  
    18.  
    19. Private Sub MyCallingProc
    20.     Call SaveData(Grid1)        'Works fine
    21.     Call SaveData(Check1)       'Works fine
    22.     Call SaveData(Text1)        'Fails with a Type Mismatch Error
    23.  
    24. End Sub

    The reason why the Call SaveData(Text1) call fails is because it VBA is assuming that I am passing the value of Text1, i.e. the text, and not the object, which is what I am trying to pass.

    Is there a way around this?

    P.S. I am using MSAccess 2000.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    The .Text property is the default property of a textbox, which means you can write:
    Text1 = "blah"
    strString = Text1
    and not
    Text1.Text = "blah"
    strString = Text1.Text
    (by the way, you can't do the first example in .Net).
    I'm not sure how you'd get around this, though. Maybe you'd have to cast the textbox to a control before passing it.
    Tengo mas preguntas que contestas

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