How to set controlsource for text box to =[DomainName] & "-->" & [Process] in VB

T

Thomas

Hi,
Actually I just want to programmatically set the
controlsource of a text box based on other text boxes on
the form or subform.

It is not difficult to set the controlsource to something
like "=[TextBox1]", but when I tried to
set it to something like "=[TextBox1] & "-->" & [TextBox2]"

I start to have problem. The I found that you can not
have "" within "" directly, so I tried to use constant
such as cQUOTE = """", it is better, but I still can not
input the character &. Then I tried to use chr (38), but
failed too (maybe I did not tried too many times).

Now my workaround is I stored the possible values for the
controlsource in a table and use an event to look up the
strings from the table based on which area I am in on the
form, then assign the looked up value to the controlsource
of the textbox.

I still really need to know how to programmatically do
this without resorting to such long-haul method I am using.


Thanks!
 
A

Allen Browne

Thomas, I don't understand your expression.

If TextBox1 contains "Fred" and Textbox2 contains "Jones", you want a text
box that reads:
Fred-->Jones
?



While I don't understand the purpose, the line of code would be:
Me.Textbox3.ControlSource = "=[TextBox1] & ""-->"" & [TextBox2]"

Note that the double-quote character within the string must be doubled, so
that Access understands it's not the end of the string.

From your subject line, you seem to think that "-->" is an operator of some
sort?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to the newsgroup. (Email address has spurious "_SpamTrap")

Thomas said:
Hi,
Actually I just want to programmatically set the
controlsource of a text box based on other text boxes on
the form or subform.

It is not difficult to set the controlsource to something
like "=[TextBox1]", but when I tried to
set it to something like "=[TextBox1] & "-->" & [TextBox2]"

I start to have problem. The I found that you can not
have "" within "" directly, so I tried to use constant
such as cQUOTE = """", it is better, but I still can not
input the character &. Then I tried to use chr (38), but
failed too (maybe I did not tried too many times).

Now my workaround is I stored the possible values for the
controlsource in a table and use an event to look up the
strings from the table based on which area I am in on the
form, then assign the looked up value to the controlsource
of the textbox.

I still really need to know how to programmatically do
this without resorting to such long-haul method I am using.


Thanks!
-----Original Message-----
Thomas, that article won't help for looking up a value in a table from a
form.

DLookup() will retrieve the value for you. Details:
Getting a value from a table
at:
http://users.bigpond.net.au/abrowne1/casu-07.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top