Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open form using variable 1

Status
Not open for further replies.

mphayesuk

IS-IT--Management
Apr 22, 2003
46
GB
Hi want I want to do is open a form using vba with the form name being a variable. eg

formnameopen$ = "form1"

DoCmd.OpenForm formnameopen$

And also use it in the code eg

Forms![formnameopen$]![EquipmentID] = selectrecord

My attempts at making this work have failed so any help would be great.

Thanks
 
Hi, how about this for the first part:

Dim formnameopen As String
formnameopen = Me.txtFrmName
DoCmd.OpenForm formnameopen, acNormal

Didn't quite understand the second part.

 
mphayesuk
For the second part, do you mean something like:
[tt]Forms(formnameopen$).TextBoxName = "Hello"[/tt]
 
Yes Remou that is what I was getting at, but instead of "hello" it can equal a variable.... But the sticking point was using a variable for the form name.

Can you or anyone help with this.

Thanks
 
Yes. Use brackets as above:
[tt]formnameopen$="Form1"
strString = "Hello"
Forms(formnameopen$).TextBoxName = strString[/tt]

This works for controls too:
[tt]strFrm = "Form1"
strCtl = "Text1"
strVal = "Hello"
Forms(strFrm).Controls(strCtl) = strVal[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top