Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

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
0
marsattack32
Asked:
marsattack32
1 Solution
 
djshortyCommented:
Are you trying to pass a reference to your form so it can be used by another module?

public sub SetFormTo(myForm as Form)
    Dim frm as Form
    Set frm = myForm
End Sub
0
 
MN_DaveCommented:
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
0
 
supunrCommented:
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!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now