Populating textbox from combo box (1 Viewer)

gizmogeek

Registered User.
Local time
Today, 08:01
Joined
Oct 3, 2007
Messages
95
I am trying to populate a textbox based on selection from combo box. Both fields are in two different subforms within the same form.

I do see the selection from the combo box fills via debug. I don't see a value in the textbox.

This is the code I am using:
Private Sub cboRequestedItems_Change()

Me.PricePerUnit.Value = Me.cboRequestedItems.Column(1)

End Sub
 

gizmogeek

Registered User.
Local time
Today, 08:01
Joined
Oct 3, 2007
Messages
95
I've also tried to point it to PricePerUnit control source. I do see when debugging that the cboRequestedItems does have the correct chose value but the PricePerUnit never populates and comes up with error 2465.

Here is the code that I used:

Private Sub cboRequestedItems_Change()

Me.Form![frmItemList subform1]![PricePerUnit] = Me.cboRequestedItems.Column(1)

End Sub
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:01
Joined
Jan 20, 2009
Messages
12,853
Code:
Me.Parent.[frmItemList subform1].Form![PricePerUnit] = Me.cboRequestedItems.Column(1)
 

gizmogeek

Registered User.
Local time
Today, 08:01
Joined
Oct 3, 2007
Messages
95
Somewhat closer. Now I get the error 2113: "The value you entered isn't valid for this field"

I still get the correct data when I hover cboRequestedInventory so I went in to the both tables to see that they have the correct data type. RequestedInventory is set as text. PricePerUnit is set to currency. I changed the data type to text just to see if I could get any data to come up on PricePerUnit on the form.

The exact data that is selected in cboRequestedInventory comes up in PricePerUnit...?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:01
Joined
Jan 20, 2009
Messages
12,853
Do you have the right column? Combo columns are indexed from zero.
 

gizmogeek

Registered User.
Local time
Today, 08:01
Joined
Oct 3, 2007
Messages
95
There's only one column in the subform cboRequestedItems so I set it to .Column(0)

The value that comes back is the ItemID and not the PricePerUnit.

Forgot to add that the ItemID and the PricePerUnit are both from the same table tblItemList.
 
Last edited:

Beetle

Duly Registered Boozer
Local time
Today, 06:01
Joined
Apr 30, 2011
Messages
1,808
Code:
Private Sub cboRequestedItems_Change()

Me.Form![frmItemList subform1]![PricePerUnit] = Me.cboRequestedItems.Column(1)

End Sub

First, you should not be using the Change event of the combo box, as this fires at every key stroke. You should be using the After Update event.

Second, some of what you've posted seems a bit confusing and/or contradictory;

I went in to the both tables to see that they have the correct data type. RequestedInventory is set as text. PricePerUnit is set to currency.

Why are you trying to store a text value in a currency field?

Somewhat closer. Now I get the error 2113: "The value you entered isn't valid for this field"

So it's not working....

The exact data that is selected in cboRequestedInventory comes up in PricePerUnit...?

Wait, so it is working...??:confused:



Why don't you post back with more details about exactly what you're attempting here, such as;

What table does the combo box get its data from?

What fields are returned by the combo (and in what order)?

Which column in the combo contains the data that you want to store in the PricePerUnit field and what is the data type?

It sounds like the PricePerUnit field is in the record source of a different sub form than the one where the combo box is, but please clarify that as well.

Lastly, why do you want to do this? If the value is already stored in one table (the one the combo box is based on), then is there a reason to store it in another table as well? It may or may not be good practice to be doing this to begin with, depending on the circumstances.
 

Users who are viewing this thread

Top Bottom