adding data when using cascading lists
Hi,
I have a question about how to handle cascading list when data is not in the list and should be added automatically.
Let's say I have a table 'A' with the fields 'B' = car brands and 'C'= car model. The table looks like:
[u]B</u> [u]C</u>
Audi A4
Audi A6
Volkswagen Golf
Dodge Viper
this data go in a second table 'D' with the fields 'E' = date, 'F' = Car brand (is the data 'B' from table 'A'), 'G' = car model (is the data 'C' from table 'A') and 'H' = licence plate number.
A form is made out of this second table with a combo box for the 'car brand' and 'car model' fields. I know how I can get the 'car model' combo box only to display the models where the combo box data of the form matches the table 'A' field 'B' brand.
What I would like to know is how I can get a message box to ask me if I want to add a new brand-model combination in the table 'A' if such a record does not exist untill now, when I add some data on the form. This question should be asked when the user wants to close the form or go to the next record. I guess the first thing to do is set the limit-to-list property for the combo boxes to 'NO'.
I'm already using something like this for another table that only has 1 field (and where the limit-to-list property is set on yes). The code I'm using there is the not in list event:
Private Sub Naam_personeelslid_NotInList(NewData As String, Response As Integer)
On Error GoTo Naam_personeelslid_NotInList_Err
Dim intantwoord As Integer
Dim strsql As String
intantwoord = MsgBox("Het personeelslid " & Chr(34) & NewData & _
Chr(34) & " staat nog niet in de lijst." & vbCrLf & _
"Wenst U deze persoon toe te voegen?" _
, vbQuestion + vbYesNo, "Ongeldige invoer personeelslid")
If intantwoord = vbYes Then
strsql = "insert into tblPersoneelsledenIKEA([Naam personeelslid]) " & _
"values ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strsql
DoCmd.SetWarnings True
MsgBox "Het personeelslid werd toegevoegd aan de lijst." _
, vbInformation, "Personeelslid toegevoegd"
Response = acDataErrAdded
Else
MsgBox "Gelieve een personeelslid uit de lijst te kiezen." _
, vbExclamation, "Ongeldige invoer personeelslid"
Response = acDataErrContinue
End If
Naam_personeelslid_NotInList_exit:
Exit Sub
Naam_personeelslid_NotInList_Err:
MsgBox Err.Description, vbCritical, "Fout"
Resume Naam_personeelslid_NotInList_exit
End Sub
This works fine If the table only has 1 field. Where do I need to change the code if I want this addition to work with these cascading list?
Thanks
|