Field dynamically updates next field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two fields that im trying to create a report off of:

1. Name
2. Box

They are linked together by a Primary Key called ID. I have two tables called Employee_Info, and Main_Data - They are designed in example below, continue down for rest of question.

Employee_info
+------------------------------------+
| ID | NAME |
+-----+-----------------------------+
| 1 | Bob Jennings |
+-----+-----------------------------+
| 2 | Etc..... |
+-----+-----------------------------+


Main_info
+------------------------------------+
| ID | Box Number |
+-----+-----------------------------+
| 1 | 1 |
+-----+-----------------------------+
| 1 | 2 |
+-----+-----------------------------+
| 1 | 5 |
+-----+-----------------------------+
| 2 | 1 |
+-----+-----------------------------+


I want to have to 2 combo boxes, the first one is Name, selecting all the names in Employee_info. I want to have it so when I select the name, it updates the second combo box to all the boxes that specific person has, since they are all different. If you can help me i would REALLY appreciate it. Thank you so much for your time!!
 
Thanks so much!!! I appreciate it!!!

MDW said:
Shouldn't be too hard. Let's call the combo boxes cboPeople and cboBoxes.

Set the RowSource property for cboPeople to something like this:
"SELECT ID, Name FROM Employee_info"
Set the ColumnCount property to 2. Make sure the BoundColumn property is set to 1. If you want to hide the ID, set the ColumnWidths propery to 0";1"

Then, in the OnChange event for cboPeople, put this code:

Dim lngID As Long
Dim strSQL As String

lngID = cboPeople.Value
strSQL = "SELECT [Box Number] FROM Main_Info WHERE ID=" & lngID
cboBoxes.RowSource = strSQL
cboBoxes.ReQuery

Make sure to set the row source type on both combo boxes to "Table/Query".

Mark Bratanov said:
I have two fields that im trying to create a report off of:

1. Name
2. Box

They are linked together by a Primary Key called ID. I have two tables called Employee_Info, and Main_Data - They are designed in example below, continue down for rest of question.

Employee_info
+------------------------------------+
| ID | NAME |
+-----+-----------------------------+
| 1 | Bob Jennings |
+-----+-----------------------------+
| 2 | Etc..... |
+-----+-----------------------------+


Main_info
+------------------------------------+
| ID | Box Number |
+-----+-----------------------------+
| 1 | 1 |
+-----+-----------------------------+
| 1 | 2 |
+-----+-----------------------------+
| 1 | 5 |
+-----+-----------------------------+
| 2 | 1 |
+-----+-----------------------------+


I want to have to 2 combo boxes, the first one is Name, selecting all the names in Employee_info. I want to have it so when I select the name, it updates the second combo box to all the boxes that specific person has, since they are all different. If you can help me i would REALLY appreciate it. Thank you so much for your time!!
 
Back
Top