How to create Dynamic Form Fields? (#Name?) Error

mrszw

Registered User.
Local time
Today, 15:13
Joined
Apr 9, 2009
Messages
11
Hi, i have created a form (Form2) based upon a query (queryA)

In queryA, there are two dynamic fields that change according to a combobox value that a user select in another form (Form1).

How do i set the fields in Form2 to be dynamic?
I tried using the following code, but it generate a #Name? error

txtAA / txtBB is the name of the textbox in my form (Form2).
"AA " & Forms!Form1.Combo1 is the exact name of the field in my query (queryA)

txtAA.ControlSource = "AA " & Forms!Form1.Combo1
txtBB.ControlSource = "BB " & Forms!Form1.Combo1

Would appreciate any help or insight

Thanks!
 
"AA " & Forms!Form1.Combo1 is the exact name of the field in my query

Your nomenclature is confusing. The name Combo1 is a field in the query but has a name like a combobox. Even it it makes sense to you it is contrary to convention and will make your code almost unreadable to most programmers.

You should name the field in the query with something that represents the nature of data and reserve names like combo1 as combobox control names.

txtAA.ControlSource = "AA " & Forms!Form1.Combo1

Your statement is referencing control called Combo1 that does not exist on Form1.

The Record Source of the form can be addressed in several variants:

.ControlSource = Forms!FormName.Form.FieldName
or more correctly:
.ControlSource = Forms!FormName.Form!FieldName
or sometimes
.ControlSource = Forms!FormName("FieldName")

Note:
.Form is a property of the the form rather than a control in its collection hence it is always preceded by the dot rather than a bang operator.
All variants of the expression will be encountered in code from time to time but never:
.ControlSource = Forms!FormName!Form!FieldName

This can be a bit confusing when ! and . seem interchanageable as all but the last operator in most long expressions.
 
Last edited:
hi, thks for the reply and explaination on the Record Source part.

btw, think my phrase ""AA " & Forms!Form1.Combo1 is the exact name of the field in my query" was misunderstood. What i meant is that the word "AA" along with the value of the combobox (Combo1), make up the name of the field. Example, "AA 09"

i've got it working nevertheless, thks again!
 

Users who are viewing this thread

Back
Top Bottom