473,396 Members | 1,982 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,396 software developers and data experts.

Dynamic autonumber on an MS Access Report

15
Hello all,

I have a report which is connected to a query that collects data based on some filters. Now, my question is, how do I make an autonumber starting from 1 get generated everytime there is a page break for a dummy text field on the report? This field is not part of any table but just a serial number. Example below.

Page 1 of report.

ID Description Qty Price
=======================
1 x x x x x x x x x x x
2 x x x x x x x x x x x x x
3
...


Page 2 of report

ID Description Qty Price
=======================
1 x x x x x x x x x x x


As you can see the value ID does not belong to any table. Just a number which starts at 1 and displays record count.

Please help. :)


Thanks!
Sep 9 '07 #1
4 3612
FishVal
2,653 Expert 2GB
Hello all,

I have a report which is connected to a query that collects data based on some filters. Now, my question is, how do I make an autonumber starting from 1 get generated everytime there is a page break for a dummy text field on the report? This field is not part of any table but just a serial number. Example below.

Page 1 of report.

ID Description Qty Price
=======================
1 x x x x x x x x x x x
2 x x x x x x x x x x x x x
3
...


Page 2 of report

ID Description Qty Price
=======================
1 x x x x x x x x x x x


As you can see the value ID does not belong to any table. Just a number which starts at 1 and displays record count.

Please help. :)


Thanks!
Hi, irkahs.

Here is one possible solution.
  • Place the following function in code module
    Expand|Select|Wrap|Line Numbers
    1. Public Function AutoNumber(ByVal varDummy As Variant, _
    2.                            Optional ByVal lngSeed As Variant) As Long
    3.  
    4.     Static lngAutoNumber As Long
    5.     If Not IsMissing(lngSeed) Then
    6.         lngAutoNumber = lngSeed
    7.     Else
    8.         AutoNumber = lngAutoNumber
    9.         lngAutoNumber = lngAutoNumber + 1
    10.     End If
    11.  
    12. End Function
    13.  
  • Create a query based on your table (lets say tblYourTable)
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblYourTable.*, AutoNumber(tblYourTable.[Any table field]) AS AutoNum FROM tblYourTable;
    [Any table field] means any table field no matter what, just to force AutoNumber function to run for each record
  • Create a report based on the query
  • In report in page header format event place the following code resetting autonumber to 1
    Expand|Select|Wrap|Line Numbers
    1. Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
    2.     AutoNumber 0, 1
    3. End Sub
    4.  

Good luck.
Sep 10 '07 #2
ADezii
8,834 Expert 8TB
Hello all,

I have a report which is connected to a query that collects data based on some filters. Now, my question is, how do I make an autonumber starting from 1 get generated everytime there is a page break for a dummy text field on the report? This field is not part of any table but just a serial number. Example below.

Page 1 of report.

ID Description Qty Price
=======================
1 x x x x x x x x x x x
2 x x x x x x x x x x x x x
3
...


Page 2 of report

ID Description Qty Price
=======================
1 x x x x x x x x x x x


As you can see the value ID does not belong to any table. Just a number which starts at 1 and displays record count.

Please help. :)


Thanks!
  1. Create an Unbound Text Box on you Report and Name it ID.
  2. In the General Declarations Section of your Report Module, enter the following line of code:
    Expand|Select|Wrap|Line Numbers
    1. Dim intCounter As Integer
  3. In the Print() Event of your Report's Detail Section, place the following code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    2.   intCounter = intCounter + 1
    3.   Me![ID] = intCounter
    4. End Sub
  4. In the Print() Event of your Report's Page Footer Section, place the following code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub PageFooterSection_Print(Cancel As Integer, PrintCount As Integer)
    2.   intCounter = 0
    3. End Sub
  5. I do believe that this is as compact as you are going to get as far as coding is concerned - it only takes 4 lines of code to do the trick, and it is independent of the Record Source.
Sep 10 '07 #3
irkahs
15
Thank you guys for the much appreciated response! It works just fine. I used the second method suggested by ADezii and it works like a charm. :)

Thank you once again.


Cheers!
Sep 10 '07 #4
ADezii
8,834 Expert 8TB
Thank you guys for the much appreciated response! It works just fine. I used the second method suggested by ADezii and it works like a charm. :)

Thank you once again.


Cheers!
You are quite welcome - always glad to help!
Sep 10 '07 #5

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

Similar topics

7
by: SharkSYA | last post by:
After canvassing ideas it appears that the way I need to do it is not possible.There are 126 rooms, more to be added, and it needs to print a report or reports showing 76 days of bookings. There...
3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
5
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: CSDunn | last post by:
Hello, I have a format issue on an Access 2000 ADP report that I am going to attempt to explain from a 'ten thousand foot view' : I have an Access 2000 ADP report that has a SQL Server 2000...
0
by: Andy_HR | last post by:
1. question when i have custom autonumber field... like Nz(DMax("ClanID", "tblClanovi")+1 how can i make it try again if someone else pressed the save button and that namber is already taken,..??...
1
by: Brad | last post by:
Thanks for taking the time to read my question. I have a table of data that has Date, Data and Category. I need to show, in a report, each Categories Data by Date. The Date has to be it's own...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.