Variable Question

D

DS

I have a field that is on several forms.
The field is called TxtManagerID.

I have a listbox to open any one of these forms.

I need to set the value of TxtManagerID on these forms so I thought this
code would work. Except I get an error message that I have to define a
class. Am I barking up the wrong tree or is there a simple solution to
this. Any help appreciated.
Thanks
DS



Dim stDocName As String
Dim stLinkCriteria As String
Dim stTxtManagerID As String
stDocName = Me.ListBackOffice.Column(1)
DoCmd.OpenForm stDocName, , , stLinkCriteria
stDocName!stTxtManagerID = Me.TxtManagerID
 
T

tina

well, you've included stLinkCriteria in the OpenForm action, but you never
set a value for the stLinkCriteria variable - suggest you remove it from the
OpenForm arguments. also, you can't refer to a form solely by its' name, and
you said that the field name in all the forms is TxtManagerID, but your code
refers to it as *st*TxtManagerID (without the asterisks, of course). the
correct syntax would be

Forms(stDocName)!TxtManagerID = Me!TxtManagerID

personally, i prefer to pass the value to the form that's being opened, and
assign it from within that form, by using the OpenArgs argument of the
OpenForm command to store the value, then assigning the stored value on each
form's Load event. the OpenForm syntax would be

DoCmd.OpenForm stDocName, _
, , , , , Me!TxtManagerID

and in each form's Load event, add the following code, as

Me!TxtManagerID = Me.OpenArgs

hth
 
D

DS

tina said:
well, you've included stLinkCriteria in the OpenForm action, but you never
set a value for the stLinkCriteria variable - suggest you remove it from the
OpenForm arguments. also, you can't refer to a form solely by its' name, and
you said that the field name in all the forms is TxtManagerID, but your code
refers to it as *st*TxtManagerID (without the asterisks, of course). the
correct syntax would be

Forms(stDocName)!TxtManagerID = Me!TxtManagerID

personally, i prefer to pass the value to the form that's being opened, and
assign it from within that form, by using the OpenArgs argument of the
OpenForm command to store the value, then assigning the stored value on each
form's Load event. the OpenForm syntax would be

DoCmd.OpenForm stDocName, _
, , , , , Me!TxtManagerID

and in each form's Load event, add the following code, as

Me!TxtManagerID = Me.OpenArgs

hth
Thanks Tina, I took you suggestion and did it with the openArg thing.
It worked great! Thank you once again!
DS
 
Top