ERROR 2108 is driving me batty!

knegrotto

New member
Local time
Today, 15:00
Joined
Oct 22, 2007
Messages
3
confused:Does any one have a solution for the problem with a setfocus following an undo and cancel event raising the following error?

Run-time error 2108: You must save the field before you execute the
SetFocus method.

I am trying to a "simple" data validation. Based on a choice in an option group (yes/no), certain data is required.

For example, if the client selects "yes", then 3 bond controls must be populated. If they are not I want to 1) "deselect option 3" 2) send a message 3) move the focus to the first missing control

Here is my code for the first required control:

Private Sub GroupClearance_BeforeUpdate(Cancel As Integer)

If Me.GroupClearance And Nz(Me.WorkRequirements, "") = "" Then
MsgBox "For Group Clearance, you must enter Work Requirements!"
Cancel = True
Me.GroupClearance.Undo
Me.WorkRequirements.SetFocus
Exit Sub
End If

No matter what I try, I get error 2108. I have tried every we I know how to force a save (Docmd.Runcommand acCmdSaveRecord, setting Me.Dirty = true).

The problem seems to arise from the record being left "dirty" from the undo and cancel event. How do I "undirty" it so I can proceed?

Thanks for your help. I have spent many hours already resaerching this and trying everything I know to no avail.:eek:
 
I would remove the Undo method because the Cancel=True should cancel the update to the control.
 
Hi KeithG,

Thanks for your reply.

That is one option that I tried initially. It does cancel the update event but leaves the "new" value in the control. To remove it and restore the initial value, the user would hit the escape key. I am trying to "do the work for them" and prevent errors.

Any other ideas?
 
K,

Look at the .OldValue property.

Me.YourControl = Me.YourControl.OldValue

Wayne
 
Thanks Wayne...

I put the following code in the AFTER update event and it works beautifully!

Me.ClearanceHolder = Me.ClearanceHolder.OldValue
Me.WorkRequirements.SetFocus
Exit Sub
End If

Thank you all for your help!
 

Users who are viewing this thread

Back
Top Bottom