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

How can I populate a text box with queried data from a combo box on the same form?

100+
P: 119
Hi there.

This is probably an easy task, but I am new to Access.

I have a combo box called cboSymbol. I want to allow a user to select a symbol and then display the corresponding description of that symbol in a text box.

I think I need a way of executing an SQL statement that looks something like this:

desString = "SELECT Description from Assets WHERE Symbol = " & cboSymbol.Value & ";"

So the answer to the query is returned and stored as a string in desString. I can then set the value of the text box to display the returned query:

txtBoxDescription.Value = desString

Does anyone know how to execute a SQL command and store the returned value as a string, or know a different way of accomplishing this?

Thanks!
Dec 1 '06 #1
Share this Question
Share on Google+
4 Replies


NeoPa
Expert Mod 15k+
P: 31,660
You need to set the ControlSource of the TextBox to point to the ComboBox required.
Dec 1 '06 #2

ADezii
Expert 5K+
P: 8,669
Hi there.

This is probably an easy task, but I am new to Access.

I have a combo box called cboSymbol. I want to allow a user to select a symbol and then display the corresponding description of that symbol in a text box.

I think I need a way of executing an SQL statement that looks something like this:

desString = "SELECT Description from Assets WHERE Symbol = " & cboSymbol.Value & ";"

So the answer to the query is returned and stored as a string in desString. I can then set the value of the text box to display the returned query:

txtBoxDescription.Value = desString

Does anyone know how to execute a SQL command and store the returned value as a string, or know a different way of accomplishing this?

Thanks!
'NeoPa's approach uses the Pull Method to populate the Text Box. You can
'also 'Push' the value into the Text Box via:

'In the AfterUpdate Event of the Combo Box
Expand|Select|Wrap|Line Numbers
  1. Me![txtBoxDescription] = DLookup("[Description]", "Assets", "[Symbol] = '" & _
  2. Me![cboSymbol] & "'")
Dec 1 '06 #3

100+
P: 119
Very nice. Thanks guys. I implemented the second method.

With the first method, I was able to link a Event Procedure to the text box [cboSymbol].[AfterUpdate]. To then update the text box, what would I do? I tried keeping the code that set the text directly...

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSymbol_AfterUpdate()
  2.     txtBoxDescription.Value = DLookup("[Description]", "Assets", _ 
  3. "[Symbol] = '" & Me![cboSymbol] & "'")
  4. End Sub
...but I got the following error message...

"You can't assign a value to this object."
Dec 1 '06 #4

NeoPa
Expert Mod 15k+
P: 31,660
You haven't included the & before the _.
Dec 2 '06 #5

Post your reply

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