Auto Populate text box based on combo box

G

Guest

Hello,

I have a combobox named "Bulk" and a text box named "Routing", I would like
the Routing box to auto populate after the user selects an option from
"Bulk". The Bulk combo box is bound to a table named "Products and bulks".
The Routing selection would be coming from the same table.

Could someone please explain this to me? I have tried different codes like:

Private Sub cboPersonID_AfterUpdate()
Me.txtPersonName.Value = Me.cboPersonID.Column(1)
End Sub

Everytime I put this in the Combo Box's afterupdate property, an error
message comes up saying it can't find the me.______

Thanks,
 
B

Beetle

Hello,

I have a combobox named "Bulk" and a text box named "Routing", I would like
the Routing box to auto populate after the user selects an option from
"Bulk". The Bulk combo box is bound to a table named "Products and bulks".
The Routing selection would be coming from the same table.

Could someone please explain this to me? I have tried different codes like:

Private Sub cboPersonID_AfterUpdate()
Me.txtPersonName.Value = Me.cboPersonID.Column(1)
End Sub

Everytime I put this in the Combo Box's afterupdate property, an error
message comes up saying it can't find the me.______

Thanks,

You are on the right track, but here are a couple of observations.

You said that your combo box is named "Bulk" and your text box is
named "Routing". However, your event code refers to a text box named
"txtPersonName" and a combo box named "cboPersonID", so you need to
verify the actual names of your controls and use those names in your
code.

Also, if you're going to use the Column property, you need to make
sure that the query that is used as the row source of your combo box
contains the "Routing" field from the table. Also verify that this
field is the second column in the query. It is a zero based numbering
system, so Column(0) is the first column, Column(1) is the second
column, etc.

HTH
 
G

Guest

Thanks for the response.

I was aware that I would need to change the control names, that was an
example. Thanks for the advice though.

On the second point, I am following all of the instructions listed, but it
still will not work.

Here is what I have in the row source property of the Bulk Combo Box:

SELECT [Product and Bulks].Bulk, [Product and Bulks].Routing FROM [Product
and Bulks] ORDER BY [Product and Bulks].Bulk, [Product and Bulks].Routing;

Bulk is the first column in the query and routing is the second.

Do you have any other ideas as to what is wrong?

Thanks,
Emily
 
G

Guest

Also, what does the column property do? I am not sure I need to use it. I
just want the simplest way to make my form work.

Thanks.
 
B

Beetle

Also, what does the column property do? I am not sure I need to use it. I
just want the simplest way to make my form work.

Thanks.









- Show quoted text -

The column property lets you refer to a field value in the query, even
if that field is not displayed in your combo box.

Your row source query looks fine, so I don't think that is the
problem. One thing about using this method is that the rtext box need
to be unbound (not bound directly to a table or query field), so you
might check the properties of your text box and make sure there is
nothing in it's "Control Source" property.
 
G

Guest

Thanks for the info.

I changed the routing text box to be unbound, but the query still will not
work. Is there a step that was left out? I am just putting the below text
into the combobox Bulk's row source. Then it should work properly, right?

Private Sub cboBulk_AfterUpdate()
Me.txtRouting.Value = Me.cboBulk.Column(1)
End Sub


The error message is that the macro doesn't exist. Do I need to create a
macro- if so how?

I have checked the columns on my query in the combobox's row source property
and they are in the order of: Bulk = the first column and Routing is second.

I don't know what else I can do to make this work!

Best regards,
Emily
 
G

Guest

Sorry I'm just geting back to you, lost track of this thread for a bit but
hopefully you're still checking it. I see your problem, at least if I'm
reading your post correctly. You don't type your code directly into the row
source of your combo box. That is where the SQL statement goes (SELECT
[Products and Bulk].[Bulk]...etc.)

Go to the event tab on the properties sheet for your combo box. Go to the
AfterUpdate event line and click the elipse to the right of it, then choose
code builder. This will open the Visual Basic screen. The following line of
code should already be there;

Private Sub cboBulk_AfterUpdate

You will just need to add;

Me.txtRouting = Me.cboBulk.Column(1)

or whichever column number you need.

you can put txtRouting.Value if you want, but you don't need to because
..Value is the default so it doesn't need to be declared explicitly

If I misunderstood you reply let me know, I'm just going off your statement

"I am just putting the below text into the combobox Bulk's row source.
Then it should work properly, right?"

HTH
 

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