Setting Textbox Control Source

StacyStacy

A "Californian" at heart!
Local time
Today, 16:57
Joined
Jan 29, 2003
Messages
159
How do I assign the value of the following query to a text box?

Me![Text543].ControlSource = "select county_nam from county where state = 'MS' and county_no = '24';"
Me![Text543].Requery

I am receivineg #NAME? in the textbox when the code above is executed.

When try running the following code as a query:

select county_nam from county where state = 'MS' and county_no = '24';

I receive a value, but it is not being displayed in the text box.

Can somone help?

Thanks!
 
You do not set a query to a textbox. You can not do it.

You can set a query or table to be the RecordSource of a form or report, or to be the RowSource of a listbox or combobox.

A textbox's ControlSource can be a field in the form's RecordSource or an expression, or nothing (unbound).
 
O.K. I changed the textbox to a combo box and added the following code:

Me![combotest].RowSource = "select county_nam from county
where state = 'MS' and county_no = '24';"
Me![combotest].Requery

The ComboBox now shows the name of the county, but I have to click on the downarrow to see the county name. Is there a way that I can display the first item in the combobox?

Thanks for your help!
 
I figured out how to select the first item in the combo box by using the following code.

Me![combotest].RowSource = "select county_nam from county where state = '" + Forms![EPL APPLICATION]![LOCATIONNAMECOMBOBOX].Column(7) + "'" + " and county_no = '" + Forms![EPL APPLICATION]![LOCATIONNAMECOMBOBOX].Column(9) + "';"
Me![combotest].Requery
Me![combotest] = Me![combotest].Column(0, 0)

What I am trying to do now is pass the value that is selected in the combobox to a textbox named txtMyTextBox.

How can I pass the selected combobox item to this textbox?

Thanks!
 
Firstly, don't use + signs unless doing mathematics. If you are concatenating then use ampersands (&).

Secondly, rather than:

Code:
Me![combotest] = Me![combotest].Column(0, 0)

use:

Code:
Me.[combotest] = Me.[combotest].ItemData(0)

And finally, in the textbox's ControlSource, put:

=[combotest].[Column](0)
 

Users who are viewing this thread

Back
Top Bottom