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
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)
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
I have also tried, without success: Forms!frmPull.Controls(strLotControl) =
... as recommended by Stuart McCall
--
Thank you,
Del
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