M
Mike
Hi,
I have been using this below code to generate invoice
numbers.
I have tblSeries and then tblInvoice in order to have
same generated number in tblseries to be written in
tblInvoice as well. I really don't know if this is a
right approach or not but I neeed some way beside the
AutoNumber to generate an Invoice Number automatically. I
have posted the code below and would really appreciate
your help and input. If the code is wrong or should there
be better way to do this. This invoice number will appear
on a form and ultimately on a report which is the invoice.
I have put it in the OnLoad Property of the frmInvoive.
Dim rst As Recordset, db As Database
Dim lngNextNumber As Long
Set db = CurrentDb
'Open tblSeries, lock, read next number, increment,
update and unlock.
Set rst = db.OpenRecordset("tblSeries", , dbDenyRead)
With rst
.MoveFirst
.Edit
lngNextNumber = ![NextNumber]
![NextNumber] = lngNextNumber + 1
.Update
Set rst = db.OpenRecordset("tblInvoice", , dbDenyRead)
With rst
..MoveFirst
..Edit
lngNextNumber = lngNextNumber
![InvoiceNumber] = lngNextNumber + 1
.AddNew
![InvoiceNumber] = lngNextNumber + 1
..Update
End With
End With
rst.Close
Set db = Nothing
End Sub
Regards,
Mike
I have been using this below code to generate invoice
numbers.
I have tblSeries and then tblInvoice in order to have
same generated number in tblseries to be written in
tblInvoice as well. I really don't know if this is a
right approach or not but I neeed some way beside the
AutoNumber to generate an Invoice Number automatically. I
have posted the code below and would really appreciate
your help and input. If the code is wrong or should there
be better way to do this. This invoice number will appear
on a form and ultimately on a report which is the invoice.
I have put it in the OnLoad Property of the frmInvoive.
Dim rst As Recordset, db As Database
Dim lngNextNumber As Long
Set db = CurrentDb
'Open tblSeries, lock, read next number, increment,
update and unlock.
Set rst = db.OpenRecordset("tblSeries", , dbDenyRead)
With rst
.MoveFirst
.Edit
lngNextNumber = ![NextNumber]
![NextNumber] = lngNextNumber + 1
.Update
Set rst = db.OpenRecordset("tblInvoice", , dbDenyRead)
With rst
..MoveFirst
..Edit
lngNextNumber = lngNextNumber
![InvoiceNumber] = lngNextNumber + 1
.AddNew
![InvoiceNumber] = lngNextNumber + 1
..Update
End With
End With
rst.Close
Set db = Nothing
End Sub
Regards,
Mike