Deleting record from Table or Query

johnbongrovey

New member
Local time
Today, 07:18
Joined
Nov 21, 2013
Messages
9
I am trying to delete a record from a table and when I pass the variable as a text value it works but when I pass as a number I am getting a mismatch error.
I have to use it as a number as I am doing other update code in my database and it is a number.

Code:
DoCmd.RunSQL "DELETE * FROM TblIssueData Where tblIssueData.SerNum = ' & Me.txtserNum & ';"


When I am using TblIssueData SerNum as a text variable in table it works but when I specify SerNum as a number in the table it gives me data mismatch error. I have to leave it as a number for other VBA code in my database. I believe it is just a syntax error but not sure where to go with it.
 
I am surprised it works at all because it should look like this:
Code:
DoCmd.RunSQL "DELETE * FROM TblIssueData Where tblIssueData.SerNum = '" & Me.txtserNum & "';"


Drop the single quotes for number fields. They are string delimiters.

Code:
DoCmd.RunSQL "DELETE * FROM TblIssueData Where tblIssueData.SerNum = " & Me.txtserNum & ";"
 
I would like to thank you for the information Galaxiom. Worked fine and good to go. The biggest issue I have with the VBA is the "') and where they are supposed to go. Another learning experience for me.
 

Users who are viewing this thread

Back
Top Bottom