Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two combo boxes, second to show fields related to first

Status
Not open for further replies.

mflower

MIS
May 6, 2001
52
NZ
Anyone knows the code for two combo boxes, cmbA and cmbB, whereby when I select a record from cmbA, it contains a related record in cmbB, therefore, when I select a record from cmbA, that related record will show in cmbB..
Thanks in advance.
 
Hi :)

I have 2 tables one is items (it_id,It_name...etc) and other is Orders (Or_id,Or_date, It_id,....etc) and item is foreign key here. I created two combo boxes like that

CmbA
----
Set its Row Source Property as: SELECT DISTINCTROW [Items].[It_id], [Items].[It_Name], [Items].[It_rate] FROM [Items];

CmbB
----
Set its Row Source Property as: SELECT DISTINCTROW [Orders].[Or_id], [Orders].[Or_Date], [Orders].[it_id], [Orders].[Amount] FROM [Orders] Where (Orders.it_id)=[Forms]![YourForm]![list1];

Click Event of CmbA

Private Sub CmbA_Click()
Dim strmsg As String
strmsg = List1
'MsgBox (strmsg)
DoCmd.requery "CmbB"
End Sub

Hope it is according to ur requirement :)

Cheers!
Aqif
 
sorry a little correct

instead of typing List1 for cmbB property...type CmbA ike

CmbB
----
Set its Row Source Property as: SELECT DISTINCTROW [Orders].[Or_id], [Orders].[Or_Date], [Orders].[it_id], [Orders].[Amount] FROM [Orders] Where (Orders.it_id)=[Forms]![YourForm]![CmbA];

CmbB will show records relevant to CmbA item selected

Cheers!
Aqif
 
Thanks for that. However, why does the value in cmbB not show in the box, but only when u click on it and the value appears in the drop down list? Also, I want the value in cmbB to be saved in another table. What's the code or best method to do this?
This is probably easy stuff to most of u out there, but does anyone know how to start from basics???
 
when cmbA will be empty meaning that u have not yet selected any value from cmbA, than CmbB will also be empty , u can set default value of cmbA to any code number (e.g IT_ID like 101 etc) and relevant values in cmbB will be displayed rite from the start. Saving value from the combo box depends upon the control source of that combo...if u could explain me what u wanna do that i can help u more.

Cheers!
Aqif
 
Hi Aqif
I actually didn't write in this part of your recommended code:

Private Sub CmbA_Click()
Dim strmsg As String
strmsg = List1
'MsgBox (strmsg)
DoCmd.requery "CmbB"
End Sub
Reason being that I actually created more than 1 combo box to reference another combo box, therefore dont know how to write this part for other combo boxes.

What I'm trying to do is when I look up a value in Combo box A, combo box B has two columns, second column is set to be equal to the value in Combo box A. However, the value which shows in Combo box B is correct but does not show up automatically in the box, rather I have to click it again to drag the value and then click on it for the value to appear. I hope I make sense. I would actually like the value to appear automatically without so much clicks..:( Is this possible..
Thanks so much.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top