I have an invoicing form with a Cmd button called new which when clicked opens a new record with todays date and increases the invoice number (number field double) by via a makro SetValue DMax(“[Invoice Number]”,”Invoice”)+1. I am trying to do some invoices automatically every month using an append query. This works perfectly other than it adds one to the last invoice number for all the new record set. In other words if the last invoice was 1000 and there are 50 new records to append they will all have an invoice number of 1001. I presume I need to wrirte some code to tell it to look at each new record one at a time but my knowledge of code is very limited. Hope someone can help. JohnMichael.
![]() |
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 Query (Access 2K)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Append Query (Access 2K)
- This topic has 8 replies, 4 voices, and was last updated 22 years, 3 months ago.
AuthorTopicWSJohnMichael
AskWoody LoungerFebruary 16, 2003 at 1:23 pm #383459Viewing 0 reply threadsAuthorReplies-
WBell
AskWoody_MVPFebruary 16, 2003 at 5:24 pm #654027The DMax process doesn’t work very well when you use an append query, as it calculates the value before it adds the record, and then keeps the same value for all records added. You could solve this in code, but if you are a learner, the process would take considerable time. I would suggest you consider an autonumber field for your invoice number – Access takes care of all the arithmetic for you, and the append query doesn’t even need to reference the invoice number. Bear in mind that will leave some holes in your number sequence when someone starts to add a new invoice manually, and then cancels the process, but it makes life much simpler. I would also suggest you put a primary key on the table which uses the Invoice field. Hope this helps.
-
WSJohnMichael
AskWoody LoungerFebruary 17, 2003 at 8:24 am #654171Thanks for replying to my append query problem WendellB but I really need to use code because I don’t know the implications of changing to an autonumber. There are 5000 invoices in my invoice table and the database comprises of 95 tables, although not all related! I might solve one problem and create a whole lot more. Anyway the knowledge could be usefull because I use the DMax +1 on quiet a few of my forms. Thanks once again. JohnMichael.
-
WScharlotte
AskWoody Lounger -
WSJohnMichael
AskWoody LoungerFebruary 18, 2003 at 7:23 pm #654550Hi Charlotte,
No I didn’t inherit the database but have built it very slowly since 1995 and in that time have managed without code. The present database actually comprises of 80 tables that are used regulary the others are backups or for test purposes, 170 queries, 67 forms and 86 reports. One reason you might consider the database is quiet big is because I am using one database for every office task from accounts to motor reports. Possibly I need to split them up into different databases? When I say one database it’s actually two because I have my tables seperate to the queries, forms and reports.
After reading a book (in the last two weeks) by J R Carter on Access, SQL and Vb I now know a bit more about code and SQL and with the aid of a book or by copying similar code and them modifying it to suit I am sure I could make something happen, I am just not sure what! Its not really the lines of code,within reason, but where to put it and how to start. I don’t know enough to see the big picture.
With regard to my Append Query problem. At the moment I click a comand button which runs a query that asks me for the month number, I enter the number click ok and approx 50 (at this time) new invoices are added to my invoice table. They are correct in every way, descriptive text, cost, date customer etc except for the invoice number which at this time is null (but could be the last number plus one for all the new invoices). I envisage adding code to this command button to run another query on the invoice table after the new records have been added to look for Null invoice numbers. Then do something like Do While Not EOF etc. The problem is what instructions do I put between this and Loop to make it add the correct invoice number to these new records? Thanks JohnMichael. -
WSpatt
AskWoody LoungerFebruary 18, 2003 at 7:52 pm #654562<>
The VBA code to put after you add the invoice records is:
Dim dbs as DAO.Database, rs as DAO.Recordset
Set dbs = CurrentDB
Set rs = dbs.OpenRecordset(“SELECT Max(InvoiceNo) as MaxInvNo FROM Table”)
Dim lngInvNo as Long
lngInvNo = rs!MaxInvNo
Set rs = dbs.OpenRecordset(“SELECT * FROM Table WHERE InvoiceNo is Null”)
Do While Not rs.EOF then
rs.Edit
lngInvNo = lngInvNo + 1
rs!InvoiceNo = lngInvNo
rs.Update
rs.MoveNext
Loop
Set rs = Nothing
Set dbs = NothingThis assumes that there is no one inputting invoices while this function runs.
Hope this helps you.
Pat -
WBell
AskWoody_MVPFebruary 18, 2003 at 9:07 pm #654580<>
Which is why this approach is a bad idea. Even if you lock the table, it can still be a problem when someone starts to add an invoice between the time you run the append query and the time you run the VBA code. What concerns do you have about autonumber fields? They are one of the basic components of Access, and intended to solve this very problem among others.
-
WSpatt
AskWoody LoungerFebruary 18, 2003 at 9:37 pm #654590Is this a batch function to post all last months invoices to the invoice table? If so, is there a date in the input table where the invoice data resides?
If there is, you could amend your code to test the invoice date for last month and just transfer those records which would leave any current months invoices in the input table. Then my code is still relevant.If the invoice number is to be a transparent number to the outside world then Wendell’s original suggestion is sound and the easiest way to go.
Pat
-
-
-
WBell
AskWoody_MVPFebruary 17, 2003 at 4:06 pm #654256To be perfectly frank, if you don’t know much about code, then using code to try to solve your problem would cause a great deal more grief than changing the Invoice Number field to an autonumber. You can change an existing field to an autonumber if it is a long integer, and if there are no weird values in it. That can be determined by doing a sort on the Invoice Number and looking at both ends of the result. As a general rule, using autonumbers for a field that has external meaning is discouraged, but in this case the number is simply a reference number that identifies a specific invoice. You should be able to test the process in a test version of your database and determine if it causes any problems – I’ve not personally encountered any other than a fairly obscure bug in the original release of Access 2000 that was fixed in Service Release SR-1a.
To solve this issue using code would require using VBA and DAO or ADO. That requires that you understand not only the syntax of VBA, but the Access object model as well, and there are significant differences depending on which data access method you choose. It would be possible for someone to construct an example set of code for you, but without knowing the exact table structure involved, it would require you doing extensive modifications to the code to make it work in your situation. Finally, doing it in code means you can no longer use an append query to add your 50 or so records, each must be added individually in a loop, and would be significantly slower – that in turn raises the possibility of someone adding an invoice manually at the same time you are running the automatic process and causing a crash because of duplicate indexes. (There are ways around that, but they involve using substantially more complex code and multiple tables.)
IMHO, the bottom line is that you are going to need to scramble to learn Access and the care and feeding of databases, so you should focus on the less painful solutions while you work to get up to speed on the intricacies of code.
-
-
Viewing 0 reply threads -

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
-
Microsoft Edge Launching Automatically?
by
healeyinpa
17 minutes ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
58 minutes ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
1 hour, 40 minutes ago -
Some advice for managing my wireless internet gateway
by
LHiggins
3 minutes ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
2 hours, 35 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
10 hours, 28 minutes ago -
Sometimes I wonder about these bots
by
Susan Bradley
6 hours, 45 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
23 hours, 25 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
1 day ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
23 hours, 50 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
20 hours, 20 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
1 day, 3 hours ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
1 day, 3 hours ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
15 hours, 42 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
1 day, 11 hours ago -
0Patch, where to begin
by
cassel23
1 day, 5 hours ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
2 days ago -
89 million Steam account details just got leaked,
by
Alex5723
1 day, 12 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
2 days, 9 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
2 days ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
1 day, 11 hours ago -
Installer program can’t read my registry
by
Peobody
4 hours, 20 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
1 day, 22 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
2 days, 5 hours ago -
False error message from eMClient
by
WSSebastian42
2 days, 20 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
3 days, 5 hours ago -
Office 2021 Perpetual for Mac
by
rebop2020
3 days, 6 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
4 hours, 26 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
3 days, 10 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
17 hours, 48 minutes 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.