Delete Qry Problem

F

Frank

I run a delete query as part of an archieve process.
However, I have a problem that occurs when the last order
entered is deleted, in that when a new order is
subsequently raised it uses DMax + 1 on the existing
order no field to calculate the next number. Obviously,
if the last entry has been archived and deleted then the
number sequence will conflict with existing archive
orders. Is there a way to prevent the record from being
deleted if its the last record in the set? Any
suggestions would be apreciated.
 
F

frank

Unable to get this to work without having to change a lot
of the existing tbl scructures and relationships.
Should I post in the programming section?

Thanks
 
F

Frank

I posted this problem into Modules, DAO & VBA and Andrew
give the following suggestion
-----Original Message-----
You could add a criterion to your delete query to specify that the ID field
must be less than the highest ID - use a DMax fuction or a subquery for the
criterion, eg

DELETE ID
FROM tblName
WHERE ID<DMax("ID","tbName");

or

DELETE ID
FROM tblName
WHERE ID<(SELECT DISTINCT Top 1 ID FROM tblName ORDER BY ID DESC;);

I responded with:

Andrew,

many thanks!!! I used the following in the criterior of
the qry and it works fine

<DMax("[OrderNo]","tblSalesOrder")

Much appreciated.
 

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

Similar Threads


Top