Last Record Question.

P

Pamela

I appologize in advance. I hale from the days of procedural programming &
took a shameful hiatus from '89-99. Anyway, I'm trying to get back into the
loop & here is my question:

I am creating an audit trail of records entered into a databse. I have the
audit trail working fine for users who attempt to add a new record. However,
if they click on clear, I want to be able to remove the latest record added
to the audit table. The unique identifier is the "record number".

I'm ashamed to ask this, but how, in VBA code, do you say something like this:


If [undo clicked] then
goto [delete last rec funct]

I know the If [undo clicked] part, but it's the telling it to delete the last
record part that I'm not clear on. All I want to do is delete the last rec
based on the RecNum.

Sorry for my pigeon BASIC. I think I'm just not seeing the forest through
the trees...
 
B

Brendan Reynolds

I'm assuming 'RecNum' is an incrementing numeric field. Here's an example
using the Orders table from the Northwind sample database ...

Using DAO ...

CurrentDb.Execute "DELETE * FROM ORDERS WHERE OrderID IN (SELECT
Max(OrderID) FROM Orders)"

Using ADO, the SQL statement remains the same, but use the Execute method of
the CurrentProject.Connection object ...

CurrentProject.Connection.Execute "DELETE * FROM ORDERS WHERE OrderID IN
(SELECT Max(OrderID) FROM Orders)"
 
P

Pamela via AccessMonster.com

Thank you for kick-starting my brain. It's been 2 yrs since I've really used
SQL and longer since I've programmed. I used: SQL1 = "DELETE * FROM
tblUserAudit WHERE RecordNum = " & CurrentRec
Worked like a charm.

Brendan said:
I'm assuming 'RecNum' is an incrementing numeric field. Here's an example
using the Orders table from the Northwind sample database ...

Using DAO ...

CurrentDb.Execute "DELETE * FROM ORDERS WHERE OrderID IN (SELECT
Max(OrderID) FROM Orders)"

Using ADO, the SQL statement remains the same, but use the Execute method of
the CurrentProject.Connection object ...

CurrentProject.Connection.Execute "DELETE * FROM ORDERS WHERE OrderID IN
(SELECT Max(OrderID) FROM Orders)"
I appologize in advance. I hale from the days of procedural programming &
took a shameful hiatus from '89-99. Anyway, I'm trying to get back into
[quoted text clipped - 23 lines]
Sorry for my pigeon BASIC. I think I'm just not seeing the forest through
the trees...
 

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