PDA

Click to See Complete Forum and Search --> : Autonumber in an Access 97 report


veseo
Sep 9th, 2007, 05:14 AM
I have two reports, each of which will be printed. I need to add an "autonumber" field to each of them, whose value will be different (+1) each time I print the report. The reports are about sales - each printed report should note the ID of the sale for storing purposes. I searched the forum and found a similar (or I thought that then) to my problem, but the problem in there was about listing the items and autonumbering them in the report, not autonumbering the report itself.

Also, the autonumber value should be restarted each year. Again for storing purposes - "Find me report #4514 from 2007" and such.

-----------

What came to me as an idea is to create a table in the DB each year (through the application, not manually) and each time I print, I add a record to that table, get the autonumber value, and then pass it to the report. But I find it way "too workaround" and in a few years, the DB will be a mess with lots of tables. Thanks in advance for any advices!

veseo
Sep 9th, 2007, 02:02 PM
I started with that method I described and no problems until I bumped into an old problem - passing the variable, containing that autonumber value to a textfield (or maybe some other type of a container?) in the report. This is the segment just BEFORE the print sequence:

myRS.AddNew
myRS.Update
myRS.Close
Set myRS = mydb.OpenRecordset("2007edn")
myRS.MoveLast
printVar = myRS!id
mydb.Close

I tried to use a textbox (called 'id') in the report as the container, which must get the value, this way I get an Access prompt as if I'm not passing the variable at all. I also tried using a label with that name, this way I don't get the prompt but the value of the variable is not passed and an empty string is printed. Here's the segment I'm using for printing:


With objaccess
.OpenCurrentDatabase filepath:="c:/db1.mdb"
.DoCmd.OpenReport "kvit_rep_edn", acPreview, WhereCondition:="[id] = " & printVar


.Visible = True

.DoCmd.Maximize
.DoCmd.Maximize
End With

One other question: How to check on form load if a table with a given name exists and if not - to create one?