From: Dennis on
It appears that you're using the BeforeUpdate event for the form/table. The
record has not yet been written to the table. Because of that, you can't look
at anything based ON that record until after it's written to the table. (As I
recall, that is)

"Afrosheen via AccessMonster.com" 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.
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201004/1
>
> .
>
From: John W. Vinson on
On Mon, 05 Apr 2010 15:52:59 GMT, "Afrosheen via AccessMonster.com"
<u46942(a)uwe> wrote:

>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.

Put a line

Me.Undo

before the move, to erase the entry on this record.
--

John W. Vinson [MVP]
From: Afrosheen via AccessMonster.com on
Thanks for all your replies.
I found out that the error was happening OnCurrent. I don't know if this is
the right thing to do, but what I did was look at where the error was being
produced and I put

if err.number <> 2108 then
msg box error
end if

It doesn't appear to have saved the record.


Dennis wrote:
>It appears that you're using the BeforeUpdate event for the form/table. The
>record has not yet been written to the table. Because of that, you can't look
>at anything based ON that record until after it's written to the table. (As I
>recall, that is)
>
>> Good morning. Good to see the board back up.
>>
>[quoted text clipped - 44 lines]
>>
>> Thanks in advance.

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

From: ruralguy via AccessMonster.com on
What we're all trying to say is you can not use DoCmd.GoToRecord , ,
acPrevious when you are sitting on a new record that is not saved whether it
is dirty or not. Are you just trying to undo the "add new record" request?


Afrosheen wrote:
>Thanks for all your replies.
>I found out that the error was happening OnCurrent. I don't know if this is
>the right thing to do, but what I did was look at where the error was being
>produced and I put
>
>if err.number <> 2108 then
>msg box error
>end if
>
>It doesn't appear to have saved the record.
>
>>It appears that you're using the BeforeUpdate event for the form/table. The
>>record has not yet been written to the table. Because of that, you can't look
>[quoted text clipped - 6 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

From: Afrosheen via AccessMonster.com on
Yes I am.
I really appreciate your help. I'm trying to get out of the New Record.

ruralguy wrote:
>What we're all trying to say is you can not use DoCmd.GoToRecord , ,
>acPrevious when you are sitting on a new record that is not saved whether it
>is dirty or not. Are you just trying to undo the "add new record" request?
>
>>Thanks for all your replies.
>>I found out that the error was happening OnCurrent. I don't know if this is
>[quoted text clipped - 12 lines]
>>>>
>>>> Thanks in advance.
>

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