Printing incremental number on report.

  • Thread starter Thread starter Mario
  • Start date Start date
M

Mario

Hi ,
I have an Access application that prints a number of waybills for
several clients .
On a form i can select the client and add the number of waybills they
need.
(for example : HP - 100 waybills)
Now I need to add an incremental number on each waybill that is
printed.
I have another table called "tblCounter" with 1 field 'CounterNo".
I'd like to use the counter to start the numbering on the waybills and
update the counter when the reports are printed.
Can someone help me with this pls.
This is the code i use now.

Sub PrintWaybill()
Dim Language
Dim dbWaybill As DAO.Database
Dim rstCurWB As DAO.Recordset
Dim RecId, Aantal, RecCount

Set dbWaybill = CurrentDb()
Set rstCurWB = dbWaybill.OpenRecordset("QryPrintSelected",
dbOpenDynaset)

With rstCurWB
RecCount = .RecordCount
End With

If RecCount = 0 Or IsNull(RecCount) Or IsEmpty(RecCount) Then
MsgBox "No clients selected to print", vbInformation +
vbOKOnly, "Error Printing"
Else

rstCurWB.MoveFirst
While Not rstCurWB.EOF

RecId = rstCurWB.Fields("OrderID").Value
Aantal = rstCurWB.Fields("AantalAWB").Value ' number of
waybills needed

DoCmd.OpenReport "RptNewWaybill", acViewPreview, ,
"[OrderID]=" & RecId, acHidden
DoCmd.SelectObject acReport, "RptNewWaybill", False
DoCmd.PrintOut , , , , Aantal
DoCmd.Close acReport, "RptNewWaybill", acSaveNo

rstCurWB.Edit
rstCurWB.Fields("PrintAWB") = False
rstCurWB.Fields("AantalAWB") = 0
rstCurWB.Update
rstCurWB.MoveNext
Wend

End If
End Sub
 
Hello again ,
I found a solution to get the incremental number on the report.
I get the number from table "tblCounter" with the recordset rstcount
and put it in a variable intCounter

In the OnPrint event in the Report Detail section I add 1 to the
counter
intcounter = intcounter +1
and set the value of the unbound textfield "TxtCounter" with the
intcounter value.
me.TxtCounter.Value = intcounter

After printing i update the counterfield with the latest intcounter
value
rstcounter.Edit
rstcounter.Fields("CounterNo") = intcounter
rstcounter.Update


Any comment on this is highly appreciated.
Thanks
Mario
 
Hi Bruce ,
Thanks for the respons. Much appreciated.
I'll keep in mind to post clear code next time.

I just needed to get each printout a number , but increment if the
report is printed several times.
For instance if i print a report 10 or 100 times the first report
needs to get the latest countnbr from the rstcounter
and increment as it prints.So 1st printout gets nbr 1, 2nd printout
get nbr 2 and so on until the report has been printed several times.
If i need to print the same report again , the the numbering
continious from the last saved counter.

I know when the report is previewed the number will increase
automaticly , but the code does not allow preview.
Users cannot preview.

Thanks again for the respons.
 
Back
Top