Open a form and set properties where the form name is stored as a variable

Posted on 2003-03-05
Medium Priority
Last Modified: 2012-05-04
I have 4 forms.   3 of the forms display information. They are called: Form_Info_A,  Form_Info_B,  Form_Info_C

The fourth form is used to select which of the other 3 is opened.  It is called:   Form_Select

On "Form_Select" I have a TextBox control named "MySelection" in which the user will enter the name of one of the three information forms.

On "Form_Select" I also have a Command Button named "cmdPrint" that will:
1) Open the selected form (A, B or C)
2) Change some properties of the selected form
3) Print the selected form
4) Close the selected form

In the OnClick event procedure behind the Command Button I can Open, Print and Close the selected form using a variable which contains the name of the selected form as follows:

Dim stDocName as String
stDocName = Me.MySelection
DoCmd.OpenForm stDocName, acNormal

' ... I need to "SET PROPERTIES" code here


MY PROBLEM is that I want to set some of the properties of the chosen form before it is printed (eg Width, Height, etc) For example I want to change the color of one of the controls named "MyControl".   If I HARDCODE the name of the selected form, and place the following code between the OPEN and PRINT commands then the properties can be set:

Forms!Form_Info_B!MyControl.BackColor = 0

This code works

HOWEVER, I do not want to hardcode one of the form names, I want to use the variable that contains the selected name.

I have tried the following but IT DOES NOT WORK

Forms!STDOCNAME!MyControl.BackColor = 0

Can somebody please tel me how to set the properties using the variable as the form name?

Thank You

Question by:PJUN
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

LordThlan earned 800 total points
ID: 8071051
If you use a variable for a form name then you would use the following:

Forms(STDOCNAME)!MyControl.BackColor = 0

This should achieve the effect you are looking for.

Expert Comment

ID: 8071065
Thee correct syntax is
Forms(stDocName).myControl.BackColor = 0

The use of Forms!Form_name!ControlName require the name of the form and not a variable representing it.


Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

770 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