Pass a string get a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Mullen

    Pass a string get a form

    Whew, it's been a while since I posted. Fogive me all for I have...

    anyway.

    I would like to be able to write a method of an object that could
    accept a string and set the corresponding form. It an easy thing to
    do if I am talking about a recordset. I could simply loop through the
    recordset collection, find the one that I wanted, and then set my
    object to the one that I found.

    But forms are seemingly different. The code out there demands that a
    form either be open or in design view. That would totally defeat the
    point of what I am trying to do. From what I find in help, if I want
    to loop through all of the forms open or not I have to go through the
    documents collection. That is fine, but when I find the form I want,
    I am still left with a string variable that I want to set to a form,
    and that just won't work. You need a text literal to set an object to
    as far as I know.

    Public frmName as form
    Public sub setThatForm(Str FormName)
    WHAT GOES HERE?

    end sub
  • Rich P

    #2
    Re: Pass a string get a form

    If you want to do something like DoCmd.OpenForm. .. for a certain
    condition, looping through the document collection may not work since I
    believe the form has to be already up and running (for which
    DoCmd.OpenFormm ... would not be an issue). But if this is something you
    had in mind, you could hardcode the list of forms in your DB into an
    array (variant array) or list them in a table. If you just want to
    access a running form, then looping through the document collection
    should get all the open forms. If you want to pass a form object to a
    procedure try this:

    Sub frm1()
    Dim frm As Form
    Set frm = Forms!frm2
    Call Procfrms(frm)
    End Sub

    Sub Procfrms(f As Form)
    Dim str1 As String
    str1 = frm!List1.Colum n(0)
    ...
    End Sub

    Or something like that (of course, in this example it would be easier to
    pass whatever was selected in the listbox (List1)). Or maybe you want
    to pass the form object to a class object to disable all the controls on
    the form while a procedure is running.

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    Working...