Hello, I would like to add a button to my form that will generate a new invoice number with the year and an incrementing number, that will work across all organisation records (so whichever company I create the invoice for, the same number won't be reused).
I have been through the forum database and found this which I think may be bang on:
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click
DoCmd.GoToRecord , , acNewRec
Dim NextNo As Long
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT NextNum FROM tblnextnum")
NextNo = rs!nextnum + 1
'now update the table
rs.Edit
rs!nextnum = NextNo
rs.Update
rs.Close
Set rs = Nothing
Me.AccountNo = NextNo
Exit_Command22_Click:
Exit Sub
My problem is I'm too much of a Rookie to know how to change this for my database as I don't understand exactly what this code does! Please can someone explain? Thanks
I have been through the forum database and found this which I think may be bang on:
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click
DoCmd.GoToRecord , , acNewRec
Dim NextNo As Long
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT NextNum FROM tblnextnum")
NextNo = rs!nextnum + 1
'now update the table
rs.Edit
rs!nextnum = NextNo
rs.Update
rs.Close
Set rs = Nothing
Me.AccountNo = NextNo
Exit_Command22_Click:
Exit Sub
My problem is I'm too much of a Rookie to know how to change this for my database as I don't understand exactly what this code does! Please can someone explain? Thanks
