problem with combo box value

blues66

Registered User.
Local time
Yesterday, 20:20
Joined
Nov 14, 2008
Messages
12
Good morning,

I'm new on this forum and it is a pleasure for me to be her to submit my question to you.
I need an help on this problems in an access (2003) form.
I'm trying to realize a input form able to record the data concerning customer order.

In this form, I have two combo boxes connected each other.
Each of these combo are taking data by two tables : [tbl_DescrPrd] and [tbl_PrdPack].

The tables have the same structure :
[tbl_DescrPrd] :
Col.1 [ID_prd] ; Col.2 [Prod Name] ; Col.3 [Packaging] ; Col.4 [Packaging description] ; Col.5 [Article code] ; Col.6 [Id_pack]

[tbl_PrdPack] :
Col.1 [ID_prd] ; Col.2 [Product]

The columns [ID-prd] are linked by relationship


The second combo (pack) is showing perfectly the results coming by the selection of the first combo (product). So no problem here.

The selection of the two combos has to input a new data in a specific table, but unfortunatly that's is not happening and the combos are inputing data referred to different coloumns. If I try to correct the "bound column", I can have success with the second combo (pack) but with the first combo (product) I receive an error.

Both the bound columns (in the combos properties) are assigned to number "1".


Here the VBA code :

Private Sub cbo_product_BeforeUpdate(Cancel As Integer)
Dim sManagerSource As String

sManagerSource = "SELECT [tbl_DescrPrd].[ID_pack], [tbl_DescrPrd].[ID_prd], [tbl_DescrPrd].[packaging] " & _
"FROM tbl_DescrPrd " & _
"WHERE [ID_prd] = " & Me.Cbo_product.Value
Me.Cbo_pack.RowSource = sManagerSource
Me.Cbo_pack.Requery
End Sub


I don't know if these data can help to have a clear picture of the problem. I can also send the specific file.

THanks a lot for all the help you can give me
 
Last edited:
You question is complex and I don't really understand it.

However it sounds like maybe you have a conflict between the bound value of one of the combos and needing to refer to a different column from the other combo.

You can refer to any column in a combo by its index ....comboboxname.column(n) where n is the column number starting at zero (unlike the bound coulmn property which starts at 1)

However you can't refer to the column index in sql (such as rowsource). To do this you make a text box whose control source refers to the column and then refer to the value of that textbox in the sql. You can make this textox not visible if you wish.

Hope that helps. Sorry if it was not what you were looking for.
 
Thanks for the answer. Probably it is better to bypass this problem.
Can you kindly tell me in which way I can copy the content of my combobox [Cbo_product] into a textbox ? and where I have to argue the event.
Soory maybe for stupid question, I've not for sure big familiarity with Access.

Thanks again in advance
 
Assuming that you do not actually mean "copy the content of my combobox into a textbox " but rather place the selected value from the combobox into a textbox, this code will do it:

Code:
Private Sub Cbo_Product_AfterUpdate()
  Me.TextBoxName = Me.Cbo_Product
End Sub
 
Thanks again for your help. It works, but the effect is still the same. It write on the textboxes the same column it was writing before on the table. There is for sure a problem ob the bounding column. I adapted this DB example to my purpose taking it from the web, but I've now some doubts abt its suitability to populate tables.
I need to filter by two combos and then populate my DB. DO you maybe have some ideas or examples?

THanks again in advance
 
Apparently the bound column is not the field you want to display (is probably an ID field) so try this, instead:
Code:
Private Sub Cbo_Product_AfterUpdate()
 Me.TextBoxName = Me.Cbo_Product.Column(1)
End Sub
 

Users who are viewing this thread

Back
Top Bottom