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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting textbox's ControlSource from code not working 1

Status
Not open for further replies.

lastout

Programmer
Apr 12, 2002
84
US
I am trying to set the ControlSource of a textbox in code but keep getting the "#Name?" result. The idea is to have the textbox show a concatenated string that includes a variable.

Me.tbxResults.ControlSource = "Search results for your query by " & varCity

But this doesn't work. Actually, even if I just say:

Me.tbxResults.ControlSource = "blah"

that doesn't work either. What am I doing wrong? lastout (the game's not over till it's over)
 
I presume u want to display the string as a literal, right? Controlsource is used to bind a textbox to a field.
Try using the 'Text' property instead.
 
You're simply missing an equal sign and some 'internal quotes' inside your quotes. Try the following:

Me.tbxResults.ControlSource = "='Search results for your query by '" & varCity

Providing varCity is recognised, this should do the trick (you might even make it a hidden control on the form.)

All of that being said, consider deedeebee's advise above. Unless you genuinly wish to dynamically alter the controlsource of a control, whilst the above will work, and have the same effect, its probably more appropriate (and simpler) to use an unbopund control, and just set the text property.




Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
deebeebee and Steve,

Thank you both for your responses. I'm going to try both but I'm starting with deebeebee's and I can't figure exactly what you are referring to when you say the "text property" of the textbox. lastout (the game's not over till it's over)
 
Also, I tried changing it to "= 'Search results for your query by'" and this does indeed return the text string but when I add

& varCity

I get an error: "The expression you entered contains invalid syntax."

lastout (the game's not over till it's over)
 
Try the following:

Dim Somevar
Somevar = "Hello world!"
Me.txtControl.ControlSource = "='Here we go" & Somevar & "'"

Put this in the form's on current event
Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Thanks, Steve. That did the trick! lastout (the game's not over till it's over)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top