LESSON 1: Never create an Append Query until you
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Append AutoNumber (XPDev)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Append AutoNumber (XPDev)
- This topic has 26 replies, 4 voices, and was last updated 21 years, 10 months ago.
AuthorTopicWSbfxtrfcmgr
AskWoody LoungerJune 29, 2003 at 4:04 pm #389776Viewing 1 reply threadAuthorReplies-
WBell
AskWoody_MVPJune 29, 2003 at 4:28 pm #689970Probably the most effective method of generating numbers is to use a single record table that contains the next number you want to use. You need to use either DAO or ADO to manage the process, but essentially what you do is trigger a routine that adds one to the stored number in that table, and then assigns that number to the new record. This should be based on the Before Insert event. The only issue you need to be really concerned about in merging your two tables is that you don’t have any duplicate numbers. I’m presuming of course that you want your invoice number to be unique.
-
WSbfxtrfcmgr
AskWoody LoungerJune 29, 2003 at 5:14 pm #689979Wendell:
I’m not certain how it goes about doing it, but frmOrderNew (DataEntry) has the invoice number (AutoNumber) locked. As soon as you begin to fill out the first entry of the form it assigns the invoice number. There is no Before Insert event for this form. I had thought perhaps I could create another text box (perhaps txtInvoiceNo2) with Max=([InvoiceNo])+1as the Control Source and then append the old records to the new table, but seeing as the old numbers exceed the existing ones (6-digit vs. 5-digit) it doesn’t seem that that would work either. All invoice numbers are unique.
In order to continue the current (5-digit) series I would somehow have to pickup on the Max number of that series, rather than the Max number of the old series (6-digit). Does that make any sense?
-
WSpatt
AskWoody LoungerJune 29, 2003 at 9:35 pm #690000The Before Insert event is not the event to put what Wendell has suggested, it should go into the BeforeUpdate event and you should check if it’s a new record.
A97 help says: >>The BeforeInsert event occurs when the user types the first character in a new record, but before the record is actually created.<<Wendell's idea is the way to go, but first you must change the Invoice number from a Autonumber to a Long Integer.
The problem with using Max(InvoiceNo)+1 is when you have multi users entering at the same time, you can easily get duplicate invoice numbers.
As regards your overlapping invoice number problem, you could put 2 ranges of numbers into the Control table (this is the single record table that Wendell talks about) as well as the NextAvailableInvoiceNo.If you need any more help, just post back.
-
WSbfxtrfcmgr
AskWoody LoungerJune 29, 2003 at 11:41 pm #690007Pat:
Long time no hear from! Good to “see” you again, and thanks for the reply! Sorry I missed you, but I shut off my email, phone, and hearing – I was in the “zone” trying to work this out. I just spent the most miserable Sunday afternoon of my life, but I did come up with a solution (of sorts) for part of the problem. Not the least bit elegant, but it does work.
I went back to the original db and created a query that deducted an amount from the InvoiceNo (6-digit) so that the highest result was equal to one number less than the InvoiceNo in the current db (5-digit). I then did a Make Table Query that included both the new and the converted InvoiceNo’s, and imported it into the current db. I then did an Append Query to update the tblMaster in the current db. All the old numbers fell right in behind the existing ones – thereby assigning any new order the correct series of Autonumbers (yuck!). I retained the old InvoiceNo and placed a txtbx on the frmOrderHistory to display next to the appended numbers. All current orders only show the current Invoice series (txtInvoiceNo), but there is a second box (txtInvoiceNoOld) that shows the old number. Like I said – it ain’t elegant!
The current frmOrderHistory now has two invoice number displays, but only the current year orders have the single entry, everything before the first of the year has two, the new (converted) number and the old one. Depending on how old the order is, you can search for it in one txtbx or the other. Not exactly pretty, but it does work, and it’s certainly better than what I had previously. However, I’m still stuck with the AutoNumber issue and would deffinitely like to get away from that – after I sober up!
If you’d like to walk me through the method you and Wendell have been discussing, I love to hear from you guys – I never want to see another AutoNumber as long as I live (at least not one that is used for display purposes) -
WSpatt
AskWoody LoungerJune 29, 2003 at 11:55 pm #690009>>If you’d like to walk me through the method you and Wendell have been discussing, I love to hear from you guys<<
All you need is to replace the Autonumber with a Long Integer number in that table (cannot remember the table name), and put the following code in the BeforeUpdate event of the form.
The table Control needs the field NextAvailableInvoiceNo defined as a Long Integer number.Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim dbs as DAO.Database, rs as DAO.Recordset
Dim lngInvoiceNo as Long
Set dbs = CurrentDB
Set rs = dbs.OpenRecordset("Control")
rs.Edit
rs!NextAvailableInvoiceNo = rs!NextAvailableInvoiceNo + 1
lngInvoiceNo = rs!NextAvailableInvoiceNo
rs.Update
txtInvoiceNo = lngInvoiceNo
Set rs = Nothing
Set dbs = Nothing
End SubYou will need to change the field txtInvoiceNo to the name of your Invoice number field on your form. I would also lock the invoice number field on your form.
-
WSbfxtrfcmgr
AskWoody LoungerJune 30, 2003 at 2:18 pm #690114Pat:
Let’s see if I follow this.
tblMaster | InvoiceNo: Change from AutoNumber to Long Integer
Create new table: tblControl | NextAvailableInvoiceNo (Long Integer)(I entered the next highest available InvoiceNo)
frmOrderNew: insert code in BeforeUpdate event.If that’s correct (and I have my doubts), then I’m getting an error (see attachment). Keep in mind that you’re dealing with someone who doesn’t even know what DAO stands for
-
WSpatt
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody LoungerJune 30, 2003 at 9:45 pm #690245No.
It’s not looking for txtProNo in tblControl is it? Because if it is, it won’t find it – it’s in tblMaster.
Did you notice what I assumed in post 269970 ? Was that all correct? -
WSpatt
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody LoungerJune 30, 2003 at 10:10 pm #690252
-
-
-
-
-
WSMarkLiquorman
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody LoungerJune 29, 2003 at 5:28 pm #689980Mark:
I’m afraid re-numbering the invoices would create an accounting nightmare!
I’m just thinking out loud here, but (considering the 6-digit issue) might I use a second txtbx to display the old invoice numbers, or would they still end up having new invoice numbers assigned from the Autonumber txtbx? This is confusing!
-
WSMarkLiquorman
AskWoody LoungerJune 30, 2003 at 11:12 am #690086Is there a chance that the new Invoice numbers will ever “catch-up” with the old numbers? If we can be sure the new invoice numbers will never get beyond 100000, then you could assign the new invoice number using this formula (I’ve just assumed field and table names):
if me.NewRecord then
InvoiceNo = Dmax(“InvoiceNo”,”tblInvoices”,”InvoiceNo<100000) + 1
end ifWhen I use this technique to create new Invoice numbers, I add this code as the last lines in my form's BeforeUpdate event.
-
WSpatt
AskWoody Lounger -
WSMarkLiquorman
AskWoody LoungerJuly 1, 2003 at 1:19 am #690326There is no multi-user issue. Assuming InvoiceNo is the Primary Key field (or at least a Unique key), then if 2 users should happen to try to write the same new InvoiceNo at the same time, one of them will get a duplicate key error message. When that person tries again, the system will select a new #.
-
WSbfxtrfcmgr
AskWoody LoungerJuly 1, 2003 at 2:54 am #690338Mark:
I owe you an apology. (I might have just sent you an e-mail, but seeing as how it was done in public, the apology should also be)
You were kind enough to reply in post 269916 when I was replying to Pat, and Pat responded to you and sent me a reply before I could get back to you. One thing lead to another and I never got back to you. That’s bad form and, well, just plain rude. I never take for granted the help and advise I receive in this forum, and least of all from someone who has been as helpful as you. It was only after reviewing the whole string that I realized my blunder. I hope you accept my humble apology.
You will see in the string that I did in fact have to resort to changing the InvoiceNo (as you already knew), but managed to come up with a way to retain the old ones for “search” purposes. The AutoNumber, on the other hand, is still an issue that Pat is working with me on (I think). Nevertheless, I do want you to know that there was no intent in my bumbling etiquette; just me being incoherent again.
You and Pat seem to be at odds as to how to go about doing this. . .so. . .uh. . .well. . .geesh!
-
WSpatt
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody LoungerJuly 1, 2003 at 12:00 pm #690445OH! Well why didn’t you just say so.
Removed “txt” from the “ProNo” code and all is well. What a great solution!Thanks so much for hanging in there with me Pat! Your patience is most admirable. Not only have you provided me with a great solution, but you also lead me through some area’s I’ve never been
. Great experiance!
-
WSMarkLiquorman
AskWoody Lounger -
WSpatt
AskWoody Lounger
-
-
-
-
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Where’s the cache today?
by
Up2you2
1 hour, 3 minutes ago -
Ascension says recent data breach affects over 430,000 patients
by
Nibbled To Death By Ducks
2 hours, 43 minutes ago -
Nintendo Switch 2 has a remote killing switch
by
Alex5723
3 hours, 3 minutes ago -
Blocking Search (on task bar) from going to web
by
HenryW
7 hours, 44 minutes ago -
Windows 10: Microsoft 365 Apps will be supported up to Oct. 10 2028
by
Alex5723
12 hours, 51 minutes ago -
Add or Remove “Ask Copilot” Context Menu in Windows 11 and 10
by
Alex5723
12 hours, 58 minutes ago -
regarding april update and may update
by
heybengbeng
14 hours, 27 minutes ago -
MS Passkey
by
pmruzicka
2 hours, 15 minutes ago -
Can’t make Opera my default browser
by
bmeacham
22 hours, 7 minutes ago -
*Some settings are managed by your organization
by
rlowe44
8 hours, 50 minutes ago -
Formatting of “Forward”ed e-mails
by
Scott Mills
21 hours, 2 minutes ago -
SmartSwitch PC Updates will only be supported through the MS Store Going Forward
by
PL1
1 day, 16 hours ago -
CISA warns of hackers targeting critical oil infrastructure
by
Nibbled To Death By Ducks
2 days, 1 hour ago -
AI slop
by
Susan Bradley
15 hours, 49 minutes ago -
Chrome : Using AI with Enhanced Protection mode
by
Alex5723
2 days, 3 hours ago -
Two blank icons
by
CR2
14 hours, 44 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
2 days, 11 hours ago -
End of 10
by
Alex5723
2 days, 14 hours ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
1 day, 12 hours ago -
test post
by
gtd12345
2 days, 20 hours ago -
Privacy and the Real ID
by
Susan Bradley
2 days, 10 hours ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
13 hours, 4 minutes ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
3 days ago -
Upgrading from Win 10
by
WSjcgc50
1 day, 12 hours ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
1 day, 16 hours ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
3 days, 16 hours ago -
The story of Windows Longhorn
by
Cybertooth
3 days, 4 hours ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
3 days, 18 hours ago -
Are manuals extinct?
by
Susan Bradley
18 hours, 56 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
4 days, 3 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.