A
Afrosheen via AccessMonster.com
Good morning. Good to see the board back up.
Here's my problem. I have a form with a staff Id. These Ids are unique
because there are no duplicates. I click on "New" for new record. Then have
the code check to see if it is a duplicate record
Private Sub StaffId_BeforeUpdate(Cancel As Integer)
10 On Error GoTo Err_Form_BeforeUpdate
20 If Not IsNull(DLookup("[staffid]", "tblMain", "[staffid] = '" & Me!
[StaffId] & "'")) Then
30 Select Case MsgBox("Sorry, This is a duplicate Staff Id Number," _
& vbCrLf & "" _
& vbCrLf & "Which means they already exist.. Try
again?" _
, vbYesNo Or vbQuestion Or vbDefaultButton1,
"Warning Warning")
Case vbYes
40 Cancel = True
50 Case vbNo
60 Me.Undo
70 Cancel = True
80 DoCmd.GoToRecord , , acPrevious
90 End Select
100 End If
Err_Form_BeforeUpdate:
110 If Err.Number <> 2501 Then
Call LogError(Err.Number, Err.Description, "Roster form before
update")
120 End If
End Sub
The problem is when I click on the "No I don't want to try again" I get this
error code
Runtime error 2108
You must save the field before you execute the GoToControl action,
GoToControl method, or the SetFocus method.
Your help would be very much appreciated on fixing this problem.
Thanks in advance.
Here's my problem. I have a form with a staff Id. These Ids are unique
because there are no duplicates. I click on "New" for new record. Then have
the code check to see if it is a duplicate record
Private Sub StaffId_BeforeUpdate(Cancel As Integer)
10 On Error GoTo Err_Form_BeforeUpdate
20 If Not IsNull(DLookup("[staffid]", "tblMain", "[staffid] = '" & Me!
[StaffId] & "'")) Then
30 Select Case MsgBox("Sorry, This is a duplicate Staff Id Number," _
& vbCrLf & "" _
& vbCrLf & "Which means they already exist.. Try
again?" _
, vbYesNo Or vbQuestion Or vbDefaultButton1,
"Warning Warning")
Case vbYes
40 Cancel = True
50 Case vbNo
60 Me.Undo
70 Cancel = True
80 DoCmd.GoToRecord , , acPrevious
90 End Select
100 End If
Err_Form_BeforeUpdate:
110 If Err.Number <> 2501 Then
Call LogError(Err.Number, Err.Description, "Roster form before
update")
120 End If
End Sub
The problem is when I click on the "No I don't want to try again" I get this
error code
Runtime error 2108
You must save the field before you execute the GoToControl action,
GoToControl method, or the SetFocus method.
Your help would be very much appreciated on fixing this problem.
Thanks in advance.