Report Counter Starting at a Precise Number

T

Telesphore

Table: tblCounter
Field: NextNumber

I want the field "NextNumber" to start at 2034, because the last time we
print the report for school fee, the number was 2033. So I will change the
new value in the table with the texbox "NextNumber" of a form "frmCounter".
This is usefull in case of errors, if we need to start again at 2034.

Having to view and print a 100 reports, how to make this value appear in a
report "rptFeeBill" and how to update automatically the field "NextNumber"
in the table?

Thank you in advance.
 
F

fredg

Table: tblCounter
Field: NextNumber

I want the field "NextNumber" to start at 2034, because the last time we
print the report for school fee, the number was 2033. So I will change the
new value in the table with the texbox "NextNumber" of a form "frmCounter".
This is usefull in case of errors, if we need to start again at 2034.

Having to view and print a 100 reports, how to make this value appear in a
report "rptFeeBill" and how to update automatically the field "NextNumber"
in the table?

Thank you in advance.

Code the Report's Report Footer Print event:
CurrentDb.Execute "Update tblCounter Set tblCounter.NextNumber =
Me.Page, dbFailOnError

Code the Reports Report Header Format event:
Me.Page = DLookUp("[NextNumber]","tblCounter")+1

You can use your form to change the stored number before you run the
report, if you have to.
 
T

Telesphore

Thank you

Here is my code according to your suggestion:

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.Page = DLookup("[NextNumber]", "tblCounter") + 1
End Sub

Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)
CurrentDb.Execute "Update tblCounter Set tblCounter.NextNumber ="
Me.Page , dbFailOnError
End Sub

The code seems correct, but nothing happens in the report. I suppose I need
a text box in the report? I try "=NextNumber()" in the Control Source, but
to no avail.

Table: tblCounter
Field: NextNumber

I want the field "NextNumber" to start at 2034, because the last time we
print the report for school fee, the number was 2033. So I will change
the
new value in the table with the texbox "NextNumber" of a form
"frmCounter".
This is usefull in case of errors, if we need to start again at 2034.

Having to view and print a 100 reports, how to make this value appear in
a
report "rptFeeBill" and how to update automatically the field
"NextNumber"
in the table?

Thank you in advance.

Code the Report's Report Footer Print event:
CurrentDb.Execute "Update tblCounter Set tblCounter.NextNumber =
Me.Page, dbFailOnError

Code the Reports Report Header Format event:
Me.Page = DLookUp("[NextNumber]","tblCounter")+1

You can use your form to change the stored number before you run the
report, if you have to.
....
 
F

fredg

Thank you

Here is my code according to your suggestion:

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.Page = DLookup("[NextNumber]", "tblCounter") + 1
End Sub

Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)
CurrentDb.Execute "Update tblCounter Set tblCounter.NextNumber ="
Me.Page , dbFailOnError
End Sub

The code seems correct, but nothing happens in the report. I suppose I need
a text box in the report? I try "=NextNumber()" in the Control Source, but
to no avail.

Table: tblCounter
Field: NextNumber

I want the field "NextNumber" to start at 2034, because the last time we
print the report for school fee, the number was 2033. So I will change
the
new value in the table with the texbox "NextNumber" of a form
"frmCounter".
This is usefull in case of errors, if we need to start again at 2034.

Having to view and print a 100 reports, how to make this value appear in
a
report "rptFeeBill" and how to update automatically the field
"NextNumber"
in the table?

Thank you in advance.

Code the Report's Report Footer Print event:
CurrentDb.Execute "Update tblCounter Set tblCounter.NextNumber =
Me.Page, dbFailOnError

Code the Reports Report Header Format event:
Me.Page = DLookUp("[NextNumber]","tblCounter")+1

You can use your form to change the stored number before you run the
report, if you have to.
...

Well the code is not quite correct, and I see it's my fault.
I left off an ampersand (&). Sorry!
Change the CurrentDb.execute line to (all on one line):

CurrentDb.Execute "Update tblCounter Set tblCounter.NextNumber = "
& Me.Page, dbFailOnError
Make sure there is a starting number value in the NextNumber field
(Enter a 0 if this is the first time the reports are run).

You do not need a control =[NextNumber] in the report.

You can test this while it's being run to see what values are being
returned. Add, in the Report Header event:
Me.Page = DLookUp(... etc)
MsgBox Me.Page

In the Report Footer event:
MsgBox Me.Page
CurrentDb.Execute .... etc.

A message will return the starting page number and the closing page
number each time the report is run.
When it's working correctly delete the message box lines.
 
Top