Renee said:
So I put that event into my form but once I say yes to the question 'Add new
name?' it gives me a msg box that says 'An error occurre. Please try again."
I know that this msg box is set up in the event so I cannot figure out where
the error is. Any ideas on how I can figure out where the error is?
Hi,
First thing add a description of the error in your code like this:
If Err Then
MsgBox "An error occurred. Please try again."
MsgBox Err.Description
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
I had a similar problem, so if your error is like:
"You cannot add or change a record because a related record is required in
table 'TblSuppliers'."
TblSuppliers
SupplierID
SupplierName
TblProducts
ProductID
SupplierID
Where (to simplify) I have 2 tables with a one-to-many-relationship between
my table TblSuppliers and my table TblProducts, with checkbox for "Enforce
Referential integrity" set to True. So when I add a new product thanks to the
combo box the recordset need to know to which SupplierID link the new
ProductName like this (entire code):
Private Sub ProductNameDropdownList_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 an available Product Name " & vbCrLf
& vbCrLf
strMsg = strMsg & "Do you want to associate the new Name?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link 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("TblProducts", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs![SupplierID] = SupplierIDDropdownList.Value
rs![ProductName] = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub