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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable in a [Form]!... name

Status
Not open for further replies.

briansmithdanisco

IS-IT--Management
Jun 13, 2007
19
US
Hi,

Is it possible to have a variable in a reference to a form name?

I have a sub-form that I want to use in several main fomrs. It calculates plant processing times. Based on a menu selectin, the different forms will be displayed with the common sub-form. The update process for the tables associated with each of the main forms will use some header data that is entered and, the data entered from the sub-form.

What I would like to do is:

Dim strFormName as String

' Set the variable based on what form button is pressed.
strFormName = gstrGlobalFormVariable

' Reference the
With rst
.Fields("TotalTimeDetail") = dteTimeCalc
.Fields("PlantLocation") = [Forms]![strFormName].Form![Plant]
.Update
End With

This will update some data on the table with the calculated data and what plant entered the data. I have tried putting quotes, and & around the "strFormName" but I always get an error that the form name can't be found.

Any ideas?
Thanks.
 
Hi

Have you tried:

[Forms](strFormName).Form![Plant]

But, I note you have .FORM in the code, suggesting this is a subform?, if I am right I think you will find you can reference the form by refereing to the subform CONTROL name, then .FORM ...etc

further you can change the subform contained within the subform control on the fly by setting the .SourceObject property of the subform control


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi KenReay,

It worked. Thanks. I knew there was a way, but I just could not find the right syntax.

Thanks again for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top