Trevor G
Registered User.
- Local time
- Today, 06:45
- Joined
- Oct 1, 2009
- Messages
- 2,361
Hi All,
It has been sometime since I have had to look at Access VBA. What I am asking is can someone look at the following code and correct it please.
I have inherited an old database with a new field to add some new invoice numbers and increment the number to each recordset by + 1. Starting at 001. I have formatted the field to a Number Field and formatted it to 000"/2015". I now need to populate over 2000 records with the sequential numbers for each record.
I have created the following code as my attempt. Of course it doesn't work!
It has been sometime since I have had to look at Access VBA. What I am asking is can someone look at the following code and correct it please.
I have inherited an old database with a new field to add some new invoice numbers and increment the number to each recordset by + 1. Starting at 001. I have formatted the field to a Number Field and formatted it to 000"/2015". I now need to populate over 2000 records with the sequential numbers for each record.
I have created the following code as my attempt. Of course it doesn't work!
Code:
Sub AddNumbertoRecords()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim counter As Long
counter = 1
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblInvoices", dbOpenDynaset)
Do While rst.EOF
rst.MoveFirst
rst.Edit
rst!["NewInvoiceNumber"] = counter + counter + 1
rst.Update
rst.MoveNext
Loop
rst.Close
rst = Nothing
End Sub