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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL-DELETE record from multiple tables referencing ctrl box

Status
Not open for further replies.

siouxsiez

Technical User
Dec 20, 2005
6
US
Hi and advanced thanks...

I am trying to set up a command button to delete a single record at a time from 3 tables. The Unique ID (below) is not the primary key but is populated across the tables when a new record is given a Unique ID. cbodelete refers to a combo box where a user can select a record (using the Unique ID) to delete. My code right now is:


Dim dbs As Database
Set dbs = CurrentDatabase

dbs.Execute "DELETE * FROM Tbl1Descriptive WHERE [Unique ID]=" + [Forms]![Delete Study]![cbodelete]
dbs.Execute "DELETE * FROM Tbl2tx details WHERE [Unique ID]=" + [Forms]![Delete Study]![cbodelete]
dbs.Execute "DELETE * FROM Tbl3endpoints WHERE [Unique ID]=" + [Forms]![Delete Study]![cbodelete]


This isn't working at all and gives an "oject required" error. When I tried WHERE Unique ID = cbodelete, I got a parameter error. Can anyone help steer me the right way?

Cluelessly,
Kate
 
Try and change this:
Code:
dbs.Execute "DELETE * FROM Tbl1Descriptive WHERE [Unique ID]=" + [Forms]![Delete Study]![cbodelete]

to this:

Code:
dbs.Execute "DELETE * FROM Tbl1Descriptive WHERE [Unique ID]=[b]&[/b] [Forms]![Delete Study]![cbodelete]"
Assuming that cbodelete is a number. if it's text then
Code:
[Unique ID]='" [b]&[/b] [Forms]![Delete Study]![cbodelete] & "'"
 
Thanks j! Unfortunately, I get the same object required error.

cbodelete uses a 3-column query as its source, of which the Unique ID is only 1... might that be a problem?

Sorry, I'm such a novice with VBA.


Kate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top