H
HDias
I created a command button in a form. My intensions are that when the button
is clicked, I would like it to create a new record using the next sequential
number.
For example the first number is: 818471. When a new record is added, the
next number is 818472. Clicked again, 818473 should appear.
In my table I added the first record using the number 818471. When I then
go to the form, the record it there. Great. When I click on the button, the
next number appears, 818472. I enter the text and all seems well until I
click the button again for the next record. This is when my problems begin.
An error appears indicating that the number has already been used. It is
again trying to use the number 818472. I don't know why this is happening.
With help I added the following VB statement to the button. Not sure if
this is correct or needs tweeking:
Private Sub cmdNew_Click()
On Error GoTo Err_cmdNew_Click
Dim db As Database
Dim rs As Recordset
Dim intID As Long
Set db = CurrentDb()
Set rs = db.OpenRecordset("EpicPolicyNumber")
intID = 0
rs.MoveLast
intID = rs.Fields("Epic Policy Number")
rs.Close
DoCmd.GoToRecord , , acNewRec
Me.EpicPolicyNumber = intID + 1
Exit_cmdNew_Click:
Exit Sub
Err_cmdNew_Click:
MsgBox Err.Description
Resume Exit_cmdNew_Click
End Sub
Any help would be greatly appreciated. Thank you!
is clicked, I would like it to create a new record using the next sequential
number.
For example the first number is: 818471. When a new record is added, the
next number is 818472. Clicked again, 818473 should appear.
In my table I added the first record using the number 818471. When I then
go to the form, the record it there. Great. When I click on the button, the
next number appears, 818472. I enter the text and all seems well until I
click the button again for the next record. This is when my problems begin.
An error appears indicating that the number has already been used. It is
again trying to use the number 818472. I don't know why this is happening.
With help I added the following VB statement to the button. Not sure if
this is correct or needs tweeking:
Private Sub cmdNew_Click()
On Error GoTo Err_cmdNew_Click
Dim db As Database
Dim rs As Recordset
Dim intID As Long
Set db = CurrentDb()
Set rs = db.OpenRecordset("EpicPolicyNumber")
intID = 0
rs.MoveLast
intID = rs.Fields("Epic Policy Number")
rs.Close
DoCmd.GoToRecord , , acNewRec
Me.EpicPolicyNumber = intID + 1
Exit_cmdNew_Click:
Exit Sub
Err_cmdNew_Click:
MsgBox Err.Description
Resume Exit_cmdNew_Click
End Sub
Any help would be greatly appreciated. Thank you!