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!

How do I access a form by its name stored in a String

Status
Not open for further replies.

SteveWillett

Programmer
Oct 14, 2011
4
US
I have a form which can be opened from two other forms. I need to be able to refer to the opening form in a VBA subroutine in the opened form. How can I do that? I have tried passing the opening form name as an OpenArgs to the open_Form method and storing it in a String variable, myCallingForm. However, this does not seem to work when I try to access the calling form from the Forms collection.

Forms![ReScreen Form]

works to access fields on the form but

Dim myCallingForm As String
myCallingForm = "ReScreen Form"
Forms![myCallingForm]

does not. Is there a way to do what I want?
 
How are ya SteveWillett . . .

Try:
Code:
[blue]   Forms(myCallingForm)[/blue]
It would also help if you set a form object and make reading easier:
Code:
[blue]   Dim frmRS as Form, myCallingForm As String
   myCallingForm = "ReScreen Form"
   Set frmRS = Forms(myCallingForm)

   frmRS.[B][I]controlname[/I][/B] = somevalue[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top