From: Afrosheen via AccessMonster.com on
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.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201004/1

From: ruralguy via AccessMonster.com on
Do your validation in the BeforeUpdate event of the CONTROL that is bound to
the StaffID instead.

Afrosheen wrote:
>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.

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

From: ruralguy via AccessMonster.com on
BTW, doing a .FindFirst with the RecordsetClone would be faster.

Afrosheen wrote:
>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.

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

From: Afrosheen via AccessMonster.com on
Thanks for getting back to me so fast.

I'm already using a record set for the form.
The BeforeUpdate control is already on the staffid. I believe the problem is
with the

DoCmd.GoToRecord , , acPrevious

because it wants to save the record first. I really don't need it saved. I
just need to go to the previous record or last record with out errors.

ruralguy wrote:
>BTW, doing a .FindFirst with the RecordsetClone would be faster.
>
>>Good morning. Good to see the board back up.
>>
>[quoted text clipped - 44 lines]
>>
>>Thanks in advance.
>

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201004/1

From: ruralguy via AccessMonster.com on
If Me.Dirty Then Me.UnDo
...will clear the Dirty flag.

Afrosheen wrote:
>Thanks for getting back to me so fast.
>
>I'm already using a record set for the form.
>The BeforeUpdate control is already on the staffid. I believe the problem is
>with the
>
>DoCmd.GoToRecord , , acPrevious
>
>because it wants to save the record first. I really don't need it saved. I
>just need to go to the previous record or last record with out errors.
>
>>BTW, doing a .FindFirst with the RecordsetClone would be faster.
>>
>[quoted text clipped - 3 lines]
>>>
>>>Thanks in advance.

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com