Variables

G

Guest

To refer to the value of a control on a form that does not have the focus I
can use the following code: Me.ControlOnFormWithFocus =
Forms!frmPull!txtControl1

How can I use a variable in this line of code in place of txtControl1? I've
tried Forms!frmPull(strLotControl) but Access tells me that it can not find
the field strLotControl.
 
S

Stuart McCall

Del said:
To refer to the value of a control on a form that does not have the focus
I
can use the following code: Me.ControlOnFormWithFocus =
Forms!frmPull!txtControl1

How can I use a variable in this line of code in place of txtControl1?
I've
tried Forms!frmPull(strLotControl) but Access tells me that it can not
find
the field strLotControl.

Access is telling you it can't find the field, which means it's searching
the form's field collection (by default), so tell it to explicitly search
the controls collection instead:

Forms!frmPull.Controls(strLotControl)
 
G

Guest

The syntax is simple enough:

Me.ControlOnFormWithFocus = strLotControl

But the issue here may be variable scoping. There are basically 3 levels of
variable scoping.
The highest level is Gloabal. It has to be Dimmed in a standard module and
is visible anywhere in the application. Now, in reality, avoid Global
varialbes. They have a problem in that an unhandled error will reset the
value of all global variables.

The Next is a module level variable. It is dimmed at the top of the module.
Any code in the module can see it. This includes standard, form, and report
modules.

The last is the local variable. It is dimmed in a procedure (function or
sub). Only the procedure in which it is declared can it be seen.

So, if the variable can't been seen in your code, it is out of scope. That
is, it is a local variable to another procedure. Two solutions are
available. Move the declaration to the module level, or make the procedure
in which you are trying to use it a function and pass the variable as an
argument. This, of course, will not work if the procedure is an event
procedure.
 
G

Guest

This gives me the same message. I was not very specific when I wrote the
message before. It says " MS Access can't find the field 'txtLot1' referred
to in your expression."
 
G

Guest

My apologies for not being more specific. The message says " MS Access can't
find the field 'txtLot1' referred to in your expression." So Access
recognizes the variable.

I have also tried, without success: Forms!frmPull.Controls(strLotControl) =
.... as recommended by Stuart McCall
 
J

J_Goddard via AccessMonster.com

Hi -

Declare the variable as public in the form frmPull, then reference it with:

forms!frmPull.MyVariable

MyVariable cannot be an array or fixed length string variable,

John


My apologies for not being more specific. The message says " MS Access can't
find the field 'txtLot1' referred to in your expression." So Access
recognizes the variable.

I have also tried, without success: Forms!frmPull.Controls(strLotControl) =
... as recommended by Stuart McCall
The syntax is simple enough:
[quoted text clipped - 28 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top