Link to home
Start Free TrialLog in
Avatar of marsattack32
marsattack32

asked on

How to set a form by a variable?

I am tyring to pass a form name into a moduels and use that form name to set the form to that form.  I can't get the codes to work, can anyone help

public sub setformto(frmname as string)
  dim frm as form
  set frm=forms(frmname)


end sub
ASKER CERTIFIED SOLUTION
Avatar of djshorty
djshorty

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Depending on what you want to do with it, you could also do something like this...

The command1 is a button on a form named form1.  Text1 is a text box on form1.

Private Sub Command1_Click()
set_Form Me
End Sub

Public Sub set_Form(frm As Form1)
frm.Text1 = "Hi There!"
End Sub
Avatar of supunr
supunr

public sub setformto(frmname as string)
     dim frm as form
     For Each f In Forms
          if (f.Name = frmName) then
               set frm=f
               Exit for
          End if
     Next
end sub

Good Luck!