Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TYPE MISMATCH help!

Status
Not open for further replies.

rogerarce

Technical User
Jan 24, 2002
57
CR
I can't have this to work. Everytime I tried to add new
information will display the type mismatch.
Thanks for your help!




Private Sub Category_NotInList(NewData As String, Response As Integer)
Dim db As Database, rs As Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' It's not a valid category."
strMsg = strMsg & " Want to link it?"
strMsg = strMsg & " Click Yes to add or No to retype it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add Category ?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblecategory", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Category = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
End Sub
 
Is Category a numeric field? If it is, then when you assign NewData to it you're trying to store a string value in a numeric field. You need to change that to:
rst!Category = CInt(NewData)
(Use "CInt" if Category is an Integer, "CLng" if it's a Long).

BTW, you should also Set rs = Nothing and Set db = Nothing before you exit the procedure. In some environments, failing to do this will prevent Access from shutting down, or will leave some of your memory unusable until you reboot. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top