Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variables

0 views
Skip to first unread message

Del

unread,
Nov 13, 2007, 12:18:01 PM11/13/07
to
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.
--
Thank you,
Del

Stuart McCall

unread,
Nov 13, 2007, 12:35:41 PM11/13/07
to
"Del" <D...@discussions.microsoft.com> wrote in message
news:36E0B7F6-F89C-4391...@microsoft.com...

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)

Klatuu

unread,
Nov 13, 2007, 12:45:00 PM11/13/07
to
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.
--
Dave Hargis, Microsoft Access MVP

Del

unread,
Nov 13, 2007, 1:46:01 PM11/13/07
to
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."
--
Thank you,
Del

Del

unread,
Nov 13, 2007, 1:51:00 PM11/13/07
to
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
--
Thank you,
Del

J_Goddard via AccessMonster.com

unread,
Nov 13, 2007, 3:08:32 PM11/13/07
to
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

Del wrote:
>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]


>> > tried Forms!frmPull(strLotControl) but Access tells me that it can not find
>> > the field strLotControl.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/200711/1

0 new messages