Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

564 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