locked
Pass parameter to Form RRS feed

  • Question

  • Hi. Is it possible to pass a parameter to a form? Im trying to design a lookup form and I need to pass a type array which will be used by the calling form later.

    Thanks.

    Monday, March 6, 2006 3:33 AM

Answers

  • If your using Access then you can specify a parameter called [OpenArgs] to the DoCmd.OpenForm() command. In here you can pass a parameter to the form. Look up the help on that as I haven't used it often.

     

    Another way would be to add a public property to the Form. Create a new instance of the form, and set the property before you open it. Here's what I mean written in Excel

    'placed in UserForm1

    Public Property Get ArrayValue() As Variant
    End Property

    Public Property Let ArrayValue(ByVal vNewValue As Variant)
    End Property

    'placed in workbook_open, create the form, set the property and show

     Dim frm As UserForm1
     frm.ArrayValue = ""
     frm.Show

    You can put code in the property to store the values or to display the values in controls, etc...

     

    Another way is to use a shared global variable stored in a module. Before you open the form set the global variables value and then when the form opens read the global variables value. I'd only use this if you'd need to.

    Monday, March 6, 2006 8:45 AM

All replies

  • what about "Declare and Raise and Handle Events" <-- I think it's really interesting <---
    Monday, March 6, 2006 4:55 AM
  • If your using Access then you can specify a parameter called [OpenArgs] to the DoCmd.OpenForm() command. In here you can pass a parameter to the form. Look up the help on that as I haven't used it often.

     

    Another way would be to add a public property to the Form. Create a new instance of the form, and set the property before you open it. Here's what I mean written in Excel

    'placed in UserForm1

    Public Property Get ArrayValue() As Variant
    End Property

    Public Property Let ArrayValue(ByVal vNewValue As Variant)
    End Property

    'placed in workbook_open, create the form, set the property and show

     Dim frm As UserForm1
     frm.ArrayValue = ""
     frm.Show

    You can put code in the property to store the values or to display the values in controls, etc...

     

    Another way is to use a shared global variable stored in a module. Before you open the form set the global variables value and then when the form opens read the global variables value. I'd only use this if you'd need to.

    Monday, March 6, 2006 8:45 AM