I'm sure that's based in good professional sense. I, OTOH, have a very controlled situation with limited consequences.As this thread clearly exposes, seasoned developers find “… but in this case it will be ok” incomprehensible![]()
it is the same as using Dmax(ContactID).Rather late, I thank you for this confirmation of what I found to work (in orig post). (Top 1 from ContactID Desc)
insert into YourTable (ContactID, FirstName) Values (2, "SampleName")
Rather late, I thank you for this confirmation of what I found to work (in orig post). (Top 1 from ContactID Desc)
It thought it had been established (very early on) that DMax will return the value of ContactID? (i.e. a number)it is the same as using Dmax(ContactID).
now, you insert a record using SQL, bringing back ContactID=2 (because you are thinking to prevent the gap).
SELECT
ProductIDs.ProductID
FROM
ProductIDs
LEFT JOIN Product ON ProductIDs.ProductID = Product.ProductID
WHERE
ProductIDs.ProductID <= (
SELECT
MAX(ProductID)
FROM
Product
) + 1
AND Product.ProductID IS NULL;
If Me.NewRecord Then
Me.ProductID.DefaultValue = """" & GetProductID & """"
End If
Private Function GetProductID()
GetProductID = Nz(DMin("ProductID", "qryProductIds"), 1)
End Function
Response = IncrementField(DataErr)
Private Function IncrementField(DataErr)
Const KEYVIOLATION = 3022
If DataErr = KEYVIOLATION Then
Me!ProductID = Nz(DMin("ProductID", "qryProductIDs"), 1)
IncrementField = acDataErrContinue
End If
End Function
be in peace with your solution then.What I was saying was that Top1... gave me the record, which is what I needed.
I think he “gets it” but is at a level of OCD (Obsessively Controlled Developing) below the bar set by many here.be in peace with your solution then.
you dont get what we are saying about autonumber field.
As you've touched upon the subject of filling gaps in a sequence of primary key values, I've never seen the point of this
I do indeed. (And yes, thank God!I think he “gets it” but is at a level of OCD (Obsessively Controlled Developing) below the bar set by many here.
You see the same gap problem in invoicing. To solve it the invoice number is generated and applied only after the invoice record is inserted. The record can only be voided, never deleted.Ken, in some systems a contiguous numbering scheme is used to show that no transactions have been missed. Happened on my watch with the U.S. Navy where my personnel management system had to exchange sequentially numbered transaction records with 18 other agencies. Of course, each agency had their own separately tracked number for each potential partner agency. If we had a numbering gap, it turned into a full-fledged auditing event that involvedinquisitorsinvestigators from Bureau of Naval Personnel, plus other officials. In Access, the "normal" autonumber field would not be acceptable and we would have to generate the next contiguous number ourselves to assure we left no gap. It's sort of analogous to documents that say "this page intentionally left blank" when in fact we KNOW that the only think blank is the auditor's mind.
Some financial systems also have that sequentially-numbered-transaction rule. While most accountants are quite decent folks, some of them can be SO anal-retentive about non-contiguous number sequences.
And THAT is why sometimes those gaps matter.
I understand that. My comment related not to maintaining an unbroken sequence, but to filling gaps in a sequence caused by the deletion of prior rows, or aborting the entry of a new row where the key is an autonumber. The ability to replace a 'missing' row with with another with the same key, which I've seen requested from time to time over the years, is what I can see no cogent justification for, beyond a desire for superficial neatness, though malice intent cannot be ruled out in some contexts.Ken, in some systems a contiguous numbering scheme is used to show that no transactions have been missed.