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

Refer to form name and field name programmatically

Status
Not open for further replies.

firsttube

Technical User
Apr 21, 2004
165
CA
I have two forms, the main form has a button that opens another form. When it does this, it sets the value of two fields in frm2:
Code:
DoCmd.OpenForm "frm2", acNormal
Forms!frm2![form_name] = "frm1"
Forms!frm2![field_name] = "field1"
Now, the OnClose event for frm2 is this:
Code:
    Dim formName As String
    Dim fieldName As String
      
    formName = Me![form_name]
    fieldName = Me![field_name]
    
      
    Forms![formName]![fieldName] = Me![field2]

Obviously, this throws the error "Cannot find form "formName".

How can one refer to a form and field programmatically using variables?
thanks


Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
Dim formName as Form
Dim fieldName as Field

this will declare those variables, the problem then being that you cant convert a string variable to a form varible.

You might try putting
Public frmName as Form
Public fldName as Field
in a module
and then when you open frm2, you can do
frmName = Me
fldName = Me.field1

-Pete
 
you may try this:
Forms(Me![form_name]).Controls(Me![field_name]).Value = Me![field2]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top