Delete Record Code

M

Michael Conroy

Each employee has a unique string that identifies them and it is the primary
key in the [tbl Employee]. When deleting this person becomes necessary I want
to capture this unique string (EID) and delete the record. However, I am
having some trouble with the syntax. When I run this it asks for a parameter
value and the employee's EID appears in the form just above the entry box.
Any help would be appreciated.

TargetEID = Me.EID
strSql = "Delete * from [tbl Employee] where [tbl Employee].EID = " &
TargetEID & ";"
DoCmd.RunSQL strSQL
 
S

SteveM

First of all, don't use RunSQL. It is obsolete and replaced by
CurrentDb.Execute.
Secondly, you need to use single quotes to represent a string within a
string. Numeric values do not need this and date values require
octothorpes(#).
Try this:

strSql = "Delete * from [tbl Employee] where [tbl Employee].EID = '" &
Me.EID & "'"
CurrentDb.Execute strSQL, dbFailOnError

Steve
 
M

Michael Conroy

Thanks Steve, that worked. What confused me was when I moused over the strSql
line the TargetEID variable changed to the employee's ID, so I thought I had
enough quotes. Thanks again.
--
Michael Conroy
Stamford, CT


SteveM said:
First of all, don't use RunSQL. It is obsolete and replaced by
CurrentDb.Execute.
Secondly, you need to use single quotes to represent a string within a
string. Numeric values do not need this and date values require
octothorpes(#).
Try this:

strSql = "Delete * from [tbl Employee] where [tbl Employee].EID = '" &
Me.EID & "'"
CurrentDb.Execute strSQL, dbFailOnError

Steve


Michael Conroy said:
Each employee has a unique string that identifies them and it is the primary
key in the [tbl Employee]. When deleting this person becomes necessary I want
to capture this unique string (EID) and delete the record. However, I am
having some trouble with the syntax. When I run this it asks for a parameter
value and the employee's EID appears in the form just above the entry box.
Any help would be appreciated.

TargetEID = Me.EID
strSql = "Delete * from [tbl Employee] where [tbl Employee].EID = " &
TargetEID & ";"
DoCmd.RunSQL strSQL
 

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