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

Calculated text box and variables 1

Status
Not open for further replies.

ramzoid

Technical User
Mar 4, 2005
12
0
0
US
I am trying to use an unbound text box to display a message based on the contents of a data-entry text box. In the sub associated with the data-entry box, the message text is stored in a string variable, sMessage. I tried simply putting =[sMessage] in the control source for the unbound box, but I get a ?Name error.

Do I need to dim this variable somewhere for it to be available to all of the objects on the form?

Should the unbound box be enabled? Locked?

Do I need some code on the data-entry box that will tell the unbound box to refresh/requery/update?

This question is a follow-up to an eariler posting about how to provide feedback on data-entry input (
Thanks for any tips!

Joe
 
If the textbox is not to be modified, I would set Enabled = no and Locked = yes. Your variable is only in the scope of your sub. You can create a public variable using Public, but generally it's bad practice.

I would recommend creating a function.

Function sMessage(num as Integer)
sMessage = "Welcome " & DLookup("Name","tblName","ID=" & num)
End Function

Your control source then becomes =sMessage(txtID)

I prefer to use VB because the control source box is so small, but you can also just set the control source ="Welcome " & DLookup("Name","tblName","ID=" & txtID)
 
Thanks! The suggestion you posted to the related thread, of just setting the name of the ubound box equal to the dlookup expression (in the sub for the data-entry box) works perfectly!

Thanks for addressing all the sub-questions!

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top