By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,638 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,638 IT Pros & Developers. It's quick & easy.

How to input text with the control name into ControlSource from VBA?

100+
P: 176
Hello.

I need a help to solve the following:

I'm intersted in having the Control Source of a textbox as following:
="Comment, " & [controlname]

When I input this from Design View into the Control Source, it works.

When I write in VBA:
Expand|Select|Wrap|Line Numbers
  1. Me.txbTextBox.ControlSource = "Comments, " & [Name]
or
Expand|Select|Wrap|Line Numbers
  1. Me.txbTextBox.ControlSource = ""Comments, " & [Name]"
Access returns the #Name? error in Form View.

Any Ideas?

Thanks for your time, Michael.
Dec 5 '06 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Try this

Expand|Select|Wrap|Line Numbers
  1. Me.txbTextBox.ControlSource = "='Comments, ' & [Name]"
  2.  
Hello.

I need a help to solve the following:

I'm intersted in having the Control Source of a textbox as following:
="Comment, " & [controlname]

When I input this from Design View into the Control Source, it works.

When I write in VBA:
Expand|Select|Wrap|Line Numbers
  1. Me.txbTextBox.ControlSource = "Comments, " & [Name]
or
Expand|Select|Wrap|Line Numbers
  1. Me.txbTextBox.ControlSource = ""Comments, " & [Name]"
Access returns the #Name? error in Form View.

Any Ideas?

Thanks for your time, Michael.
Dec 5 '06 #2

100+
P: 176
Try this

Expand|Select|Wrap|Line Numbers
  1. Me.txbTextBox.ControlSource = "='Comments, ' & [Name]"
  2.  
Yes, it works!
A pretty peculiar way of syntax to the unexperinced user of VBA as myself, or - "how should I've known this?!".
:)
Thanks.
Dec 5 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Yes, it works!
A pretty peculiar way of syntax to the unexperinced user of VBA as myself, or - "how should I've known this?!".
:)
Thanks.
Rule is when you're passing a value as a string that contains a string the contained string has to be in single quotes or the engine views each quote as the beginning or end of a string.

The engine probably would put in the = sign but it's better to add it to be sure.

You learn something new every day. :)

Mary
Dec 5 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.