mraetrudeaujr
Technical User
I have a database where the users are manually inputting the next "PRSLOG" number. They end up going to the last record, adding one number to it, and then putting it in the field. They would like me to 'automate' this so that every time they click the "add new record" button it automatically gives them the next sequential "PRSLOG" number. I searched this area and found some code that looks like it would work, but it didn't. It was posted by 'dyarwood'. It worked for the user that posted his question, but I get errors when I run it (after modifying it to fit my database). Here is the posted code:
...and here is the code modified for my database:
So what do I need to make this work?
Table name=2005 Log
Field name=PRSLOG
Code:
Private Sub cmdAddRecord_Click()
On Error GoTo Err_cmdAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'increment service id number
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim rcd As ADODB.Recordset
Set rcd = New ADODB.Recordset
rcd.Open "tblService", cnn, adOpenForwardOnly,_ adLockOptimistic
i = DMax("[ServiceID]", "tblService")
i = i + 1
rcd.MoveLast
rcd.MoveLast
rcd.Fields(a) = i
Exit_cmdAddRecord_Click:
Exit Sub
Err_cmdAddRecord_Click:
MsgBox Err.Description
Resume Exit_cmdAddRecord_Click
End Sub
Code:
Private Sub cmdAddRecord_Click()
On Error GoTo Err_cmdAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'increment service id number
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim rcd As ADODB.Recordset
Set rcd = New ADODB.Recordset
rcd.Open "2005 Log", cnn, adOpenForwardOnly,_ adLockOptimistic
i = DMax("[PRSLOG]", "2005")
i = i + 1
rcd.MoveLast
rcd.MoveLast
rcd.Fields(0) = i
Exit_cmdAddRecord_Click:
Exit Sub
Err_cmdAddRecord_Click:
MsgBox Err.Description
Resume Exit_cmdAddRecord_Click
End Sub
Table name=2005 Log
Field name=PRSLOG