Not In List Event

R

Renee

So I put this 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 occurred. 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?
This is how the event looks:
Private Sub VENDOR_ID_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 AE Name " & vbCrLf &
vbCrLf
strMsg = strMsg & "Do you want to associate the new Name to the current
DLSAF?"
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("PARTS VENDOR T", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!VENDOR_ID = 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
 
K

Klatuu

There are too many possible errors in the scenerio to even hazard a guess. I
suggest you comment out that section of code, then run the routine. It will
tell you what the error is. Post back when you know and we can help you
correct the problem.
 
K

Ken Snell \(MVP\)

Renee -

It's best to stay with the thread that is already open and working for your
problem. Posting a new thread means that people will spend additional time
answering a duplicate question, and won't have the history of the thread
while reading/considering the new thread.

--

Ken Snell
<MS ACCESS MVP>

Renee said:
So I put this event into my form but once I say yes to the question 'Add
new

< snipped >
 
R

Renee

Thank you both for you help I managed to figure it out on my own. I need
square brakets around my field name and I didn't have that. Thanks any.

Renee
 

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