How to set a form by a variable?

Posted on 2003-03-06
Medium Priority
Last Modified: 2010-05-01
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
Question by:marsattack32
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

djshorty earned 90 total points
ID: 8085390
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

Expert Comment

ID: 8085444
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
LVL 11

Expert Comment

ID: 8085558
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
end sub

Good Luck!

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question