PC Review


Reply
Thread Tools Rate Thread

Delete record problem

 
 
frank
Guest
Posts: n/a
 
      8th Sep 2003
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. So, is there a way to prevent the record from
being deleted if its the last record in the set? Any
suggestions would be apreciated.
..
Code examples stc?

 
Reply With Quote
 
 
 
 
Andrew Smith
Guest
Posts: n/a
 
      8th Sep 2003
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;


"frank" <(E-Mail Removed)> wrote in message
news:3ee501c37646$afc9c490$(E-Mail Removed)...
> 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. So, is there a way to prevent the record from
> being deleted if its the last record in the set? Any
> suggestions would be apreciated.
> .
> Code examples stc?
>



 
Reply With Quote
 
frank
Guest
Posts: n/a
 
      8th Sep 2003
Andrew,

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

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

Much appreciated.


>-----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;
>
>
>"frank" <(E-Mail Removed)> wrote in message
>news:3ee501c37646$afc9c490$(E-Mail Removed)...
>> 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. So, is there a way to prevent the record from
>> being deleted if its the last record in the set? Any
>> suggestions would be apreciated.
>> .
>> Code examples stc?
>>

>
>
>.
>

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      9th Sep 2003
"frank" <(E-Mail Removed)> wrote in
news:3ee501c37646$afc9c490$(E-Mail Removed):

> I run a delete query as part of an archieve process.
>


The other plan is simply not to delete the records: you can set a flag in a
"IsArchived" field and use the queries to excluded archived records. That
way, you can still summarise and count all records without having to mess
about with UNION queries and what not: there is no chance of getting
duplicates into the archive table; and your numbering system carries on
regardless.

One thought, though. Since you are now complaining about the one thing that
people find disagreeable with autonumbers not having (i.e.
consecutiveness), then why not simply use an autonumber?

All the best



Tim F

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error 2501 Problem when DoubleClicking to Delete Record is Cancell =?Utf-8?B?VGVk?= Microsoft Access Form Coding 14 3rd Mar 2005 04:06 PM
Delete record problem. =?Utf-8?B?SmF5?= Microsoft Access Database Table Design 2 17th May 2004 12:05 AM
Macro to delete record and validation problem Bob Microsoft Excel Programming 5 9th Dec 2003 01:35 PM
HELP! Query delete record problem... jules Microsoft Access Queries 1 16th Nov 2003 03:47 PM
Strange problem: Dataset add/delete fail on record 2-3 bouundary JerryK Microsoft ADO .NET 0 18th Aug 2003 09:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:16 AM.