Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Control Source of text box to a public variable 1

Status
Not open for further replies.

ajaeger

Technical User
Feb 6, 2003
201
US
On the On Load event of a form, I'm trying to set the control source of a text box to a public variable. The code I've tried is:

Me.txtLoginAs.ControlSource = "=" & pstrUserIDValidate

I get #Name? in that field.

Thanks.



Anna Jaeger
iMIS Database Support
 
when you manually put in a control source it looks like
fieldName
not
=fieldName

So not "=
 
If you want to return a value instead then you could build a function

public function getUserID() as string
getUserID = pstrUserIDValidate
end function

then the control source is
=getUserID
 
I have set-up the function as you specified:

Public Function getUserID() As String
getUserID = pstrUserIDValidate
End Function


On loading the form, the code is:

Private Sub Form_Load()
MsgBox getUserID
Me.txtLoginAs.ControlSource = getUserID
End Sub


The MsgBox returns the correct UserID, but the text box on the form still reads #Name?

Anna Jaeger
iMIS Database Support
 
Sorry for the confusion. My assumption is that you no longer would need set the control source in code. Build the function and then, just go to the controls properties and type in: =getUserID()

If you had to do it in code. Then it would be
me.txtLoginAs.ControlSource = "=getUserID()"
But I can not imagine why you would need to do that
 
Me.txtLoginAs.ControlSource = "=" & pstrUserIDValidate
what about this ?
Me.txtLoginAs.ControlSource = "=""" & pstrUserIDValidate & """"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top