R
rnjalston via AccessMonster.com
I have 4 comboboxes that are each filtered from the previous (Lets say they
are comboboxes A thru D). They are functioning properly. When I enter a
record that is not in the list for Combobox A, it says not in list would you
like to add it?. Answer yes and record is added. Now to combobox B, same
thing happens. However, They should be related. What code do I need to add
to have the record added to combobox B to be related to Combobox A?
Here is the code for the NotInList:
' If Entered Product is not in List allow add.
Private Sub cboProduct_NotInList(NewData As String, Response As Integer)
'Supress the default error message.
Response = acDataErrContinue
'Ask user if they want to add the new Product to the list/database
If MsgBox(NewData & " is not in list of Products. Add it?", vbYesNo) =
vbYes Then
Dim db As Database
Dim rstProducts As Recordset
Dim sqlProducts As String
Set db = CurrentDb()
sqlProducts = "Select * From Products"
'Create a new recordset to add the new PRODUCT to the database.
Set rstProducts = db.OpenRecordset(sqlProducts, dbOpenDynaset)
rstProducts.AddNew
rstProducts![Product] = NewData
rstProducts![ManufacturerID] = cboMfg.Value
rstProducts.Update
'Inform the combobox that the desired item has been added to the list.
Response = acDataErrAdded
rstProducts.Close 'Close the recordest
End If
End Sub
are comboboxes A thru D). They are functioning properly. When I enter a
record that is not in the list for Combobox A, it says not in list would you
like to add it?. Answer yes and record is added. Now to combobox B, same
thing happens. However, They should be related. What code do I need to add
to have the record added to combobox B to be related to Combobox A?
Here is the code for the NotInList:
' If Entered Product is not in List allow add.
Private Sub cboProduct_NotInList(NewData As String, Response As Integer)
'Supress the default error message.
Response = acDataErrContinue
'Ask user if they want to add the new Product to the list/database
If MsgBox(NewData & " is not in list of Products. Add it?", vbYesNo) =
vbYes Then
Dim db As Database
Dim rstProducts As Recordset
Dim sqlProducts As String
Set db = CurrentDb()
sqlProducts = "Select * From Products"
'Create a new recordset to add the new PRODUCT to the database.
Set rstProducts = db.OpenRecordset(sqlProducts, dbOpenDynaset)
rstProducts.AddNew
rstProducts![Product] = NewData
rstProducts![ManufacturerID] = cboMfg.Value
rstProducts.Update
'Inform the combobox that the desired item has been added to the list.
Response = acDataErrAdded
rstProducts.Close 'Close the recordest
End If
End Sub