SQL delete statement

B

Beth

I expect this is a very simple question, but I am new to writing VB code.
I currently have a button on a form that runs a delete query that deletes
all the records in a table (tblStudents) where the primary key is StudentID.

I would like to make a SQL statement in a VBA module to do delete all these
records, but in code and not by calling a query. The reason is that I am
trying to remove my queries from the database and put their actions in code
so they are not visible when I make an mde file.

If someone could help me understand what I need to write in the code to make
this work, I would really appreciate it. I have seen some articles on the
subject, but I was unable to follow them and make them work.

Thanks,
Beth
 
B

Brian Bastl

Beth,
You'll have to change the references as required, but the following should
give you an idea:

Dim stDelete as String

stDelete = "DELETE * FROM MyTable " & _
"WHERE StudentID =" & MyStudentIDControl

CurrentDb.Execute stDelete, dbFailOnError

Brian
 
T

TC

Beth said:
I currently have a button on a form that runs a delete query that deletes
all the records in a table (tblStudents) where the primary key is StudentID.


Just a side comment: by definition, every record in a table has a
different value of the primary key field(s). If StudentID is the
primary key of that table, there can not be more than one record with
the same StudentID.

HTH,
TC (MVP Access)
(off tomorrow)
 

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