Help to Debug code

Debased

Registered User.
Local time
Today, 11:39
Joined
Mar 11, 2004
Messages
112
I have a form with a date field the user completes upon completing the form. I want them to check one of the check boxes in a section on the form before exiting. I cannot put this procedure in the form's BeforeUpdate event because the user must be allowed to edit the form several times prior to finishing with it. I use the code below in the date field BeforeUpdate for this purpose and it works except it will not allow the focus to be set back to the first check box in the section. If I eliminate the err routine this is the error message I get:

Run-time error '2108':
You must save the filed before you execute the GoToControl action, the GoToControl method. or the SetFocus methos.


Private Sub dteDateCompleteQM_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_dteDateCompleteQM

'Force user to check one of the boxes in the Outcome section.

If ynPredictable.Value = False And ynUnpred.Value = False _
And ynMargDeviation.Value = False And ynSigDeviation.Value = False _
And ynNAOutcome.Value = False Then

MsgBox "You must select at least one box in the OUTCOME Section!"

DoCmd.CancelEvent
Me!dteDateCompleteQM.Undo
ynPredictable.SetFocus
End If

Exit_dteDateCompleteQM:
Exit Sub

Err_dteDateCompleteQM:

End Sub


I have used the SetFocus method many times and never received this error.
Any ideas? Thanks
 
Thanks for your reply Pat.

The problem with putting it in the BeforeUpdate event of the form is that the user has to be allowed to edit the form perhaps many times prior to entering the date. The date field is only entered once the transaction is completely finished. If I put the code in the BeforeUpdate event then the user is forced to make a choice they may not be prepared to make!
Any ideas?
 
Last edited:
Yes I tried that with your version however, it still will not reset the focus ...without the err routine the same error in my original post (2108) comes up. However, I can live with the fact that it cancels and clears the date field. Thanks for you replies.
By the way Pat, I read a thread the other day about a book you were working on but never could find follow up on it. I wrote an email to this forum but got no reply. Did you ever finish it? and if so, where could I get a copy? You have been a great help to me in the short time I have been a member. Take care!
 

Users who are viewing this thread

Back
Top Bottom