Problem with NotInList Code

T

Tony Williams

I have two combo boxes on different forms but both called cmbmaincompany.
On form1 the the row source is:
SELECT tblCompany.cmbCompany FROM tblCompany ORDER BY tblCompany.cmbCompany;

On form2 the rowsource is:
SELECT tblCompany.cmbCompany, tblCompany.txtEuroIndicator FROM tblCompany
WHERE (((tblCompany.txtEuroIndicator)=Yes));

I have the Limit toList properties on both forms set to YES and the On
NotinList property has this code:
Private Sub cmbmaincompany_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not on the list of companies." & vbCrLf
& " Do you want to add them to the current List?" & vbCrLf & " Click Yes to
Add or No to re-type it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblCompany", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!cmbCompany = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded

End If
End If
Set db = Nothing
Set rs = Nothing
End Sub

Form1 works fine and will allow me to add a new company but form2 gives me
the message box to add a new name but then I get the error message "An
error occurred. Please try again."

Is it because of the WHERE clause in the second form and if so what can I do
about it?

Many thanks
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top