I have finally gotten up this this as per code below and it does insert the
value into the combo but now I need to get it to synchronise with the Subform
but don't know how to do that... I have Requery procedure both on the Main
form and the combo box AfterUpdate Events but nothing seems to work until I
close and open the form again.... Any ideas on this? The code I got at the
moment is shown below:
Private Sub cmbCrop_NotInList(NewData As String, Response As Integer)
On Error GoTo cmbCrop_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Crop " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "RCL Crops")
If intAnswer = vbYes Then
strSQL = "INSERT INTO Crops([CropName]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "Your new Crop has been added to the list." _
, vbInformation, "RCL Crops"
Response = acDataErrAdded
Else
MsgBox "Please choose a Crop from the list." _
, vbInformation, "RCL Crops"
Response = acDataErrContinue
End If
cmbCrop_NotInList_Exit:
Exit Sub
cmbCrop_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume cmbCrop_NotInList_Exit
End Sub