Not in List Error

L

Lez

Hi Guys,

I have added this code to a combo I have and keep getting an error message,
can anyone tell me whats wrong with this code please



Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not an available CITY " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to associate the new CITY to the current
List?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type
it."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Source?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblcity", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Source = 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
 
D

Douglas J. Steele

It would help to know the exact error message you're getting.

If all you're getting is the message box saying "An error occurred. Please
try again", change your code from

MsgBox "An error occurred. Please try again."

to

MsgBox Err.Number & " (" & Err.Description & ") occurred. Please try
again."
 
L

Lez

Hi Douglas,

The error I get is :

3265( item not found in this collection.) occurred. Please try again.

Thanks
Lez
 
D

Douglas J. Steele

Hmm, I'm sure I replied to this earlier, but the error message implies that
tblcity doesn't have a field named Source. Assuming that the field should be
something like City or CityName, fix the line of code

rs!Source = NewData
 

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