Code not working

R

rblivewire

I am trying to add a name to the combo box after a user puts it in if
it is not already in the box. Found this on the internet. I changed
the Set rs = db.OpenRecordset("tblAE", dbOpenDynaset) to Set rs =
db.OpenRecordset("Tool Tracking List", dbOpenDynaset). It seems as if
the code skips and goes straight to the errorr message: MsgBox "An
error occurred. Please try again." The no works fine, but I can't get
it to save the entry in the combo box. Anyone see anything wrong?


Private Sub Project_Requestor_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("Tool Tracking List", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!AEName = NewData
rs.Update

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

rs.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub
 
D

Douglas J. Steele

It's probably because of the spaces in your table (or is it query?) name.

Try:

db.OpenRecordset("[Tool Tracking List]", dbOpenDynaset)

You might want to follow the advice of most of us and never put spaces in
your names.
 

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

Similar Threads


Top