473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

+1 in each row of query

Hello

I am trying to write a query which will ultimately feed a report that will print out invoices for each of my clients. I currently have a query that pulls each client's name and amount due. I now need to add an invoice number. I want these to be sequential. Is there a way to get each row in the query to increase by 1? I know this is possible within the Report by using the Running Sum property, but I really need this is the query.

Would appreciate any insight!

Thanks :)
Oct 26 '09 #1
6 2783
Can you just add an autonumber field to the table? That would do it for you. Or did I misunderstand?
Oct 26 '09 #2
ChipR
1,287 Expert 1GB
If this is actually an invoice number, I think you would want it to be permanent, and therefore part of a table. You don't want to print an invoice for your customer, then next time you run the query, get a difference number assigned to the record.
Oct 26 '09 #3
So question becomes: How do I get this autonumber to adjust each month if I have a static table? Currently I manually go through and change the invoice numbers by taking the last invoice number used the prior month and adding 1 to it and then type this sequentially all the way down my client list. Is there an update query I can run that can do this?
Oct 26 '09 #4
ChipR
1,287 Expert 1GB
I guess I'm not clear on exactly what your requirements are. What good is an invoice number if you are going to just change it?
If you are going to have an invoice number, it would normally refer to an object which is an invoice. Objects are represented by records which are stored in tables. This implies that you have a table of invoices.
Oct 26 '09 #5
ADezii
8,834 Expert 8TB
@elaspina
I do have a work-around solution that will automate the process of sequentially numbering the Invoices from the Last Entered, but it is a stretch. I'll just wait and see what, if any, solutions are provided to you.
Oct 26 '09 #6
ADezii
8,834 Expert 8TB
Assuming your Original Table is named tblInvoices and contains a Field uniquely identifying the Invoice Number named [InvoiceID]:
  1. Change your SELECT QUERY to a MAKE TABLE QUERY, but do NOT include the [InvoiceID] Field. Name the newly created Table tblInvoicesNew.
  2. Add a Field to tblInvoicesNew named [InvoiceID]. This Field must be a LONG INTEGER and NOT AutoNumber, or be a Primary Key.
  3. Execute the following code:
    Expand|Select|Wrap|Line Numbers
    1. Dim MyDB As DAO.Database
    2. Dim rstInvoice As DAO.Recordset
    3. Dim lngLastInvoiceID As Long
    4. Dim lngCounter As Long
    5.  
    6. lngCounter = 0      'Initialize
    7.  
    8. Set MyDB = CurrentDb
    9. Set rstInvoice = MyDB.OpenRecordset("tblInvoicesNew", dbOpenDynaset)
    10.  
    11. 'Assuming your Original Table is named tblInvoices and contains a
    12. 'Field named [InvoiceID], and contains Records (simplified Version)
    13. lngLastInvoiceID = DMax("[InvoiceID]", "tblInvoices")
    14.  
    15. With rstInvoice
    16.   Do While Not .EOF
    17.     lngCounter = lngCounter + 1
    18.       .Edit
    19.         ![InvoiceID] = lngLastInvoiceID + lngCounter
    20.       .Update
    21.         .MoveNext
    22.   Loop
    23. End With
    24.  
    25. rstInvoice.Close
    26. Set rstInvoice = Nothing
  4. tblInvoicesNew will now consist of Sequentially Number Invoice IDs starting from 1+ the Last [InvoiceID] in tblInvoices.
  5. Make tblInvoicesNew the Record Source for your Report, and you should be in business.
Oct 27 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tanamon | last post by:
Hello All, I am a MySQL newbie trying to write a query that selects file_name records possessing the highest numbered version for that unique file_name. I show sample data and two trial queries...
3
by: J Smith | last post by:
I'm making a website where each page has the same design, obviously its a bad idea to put the same code/html in each page so what is the best way to do this? What I'm doing at the moment is...
6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
1
by: Chasing Gates | last post by:
I have created a database that brings in a new table weekly. I then made a separate query for each sales rep and a separate report for each rep. (The reports are all identical but call different...
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
6
by: geronimo_me | last post by:
I have 20 queries that compare fields in one table with fields in another table - the query results are the records that do not match in Table1 and Table2. ie Table1 DOB 28/02/78 Table2 DOB...
1
by: tHeRoBeRtMiTcHeLL | last post by:
Below is an earlier post to an Excel Group.. ....but I thought that there might be a way to do this in Access by importing data and then creating append and/or update query. I would most certainly...
1
by: Kevin.S.Campbell | last post by:
Greetings, I'm trying to run a sql query on a continous form. I have the query working correctly the way I want it. I want this query to be displayed on the form in the text box on the load...
9
by: MLH | last post by:
I have a source query (qryITSLetterList) feeding rows containing name, addr, city, state, zip and VehicleID to a report (rptITSnotices). The query may contain 1-to-5 records resulting in 1-to-5...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.