Cancel timer event if criteria not met


K

Kurt

I have a popup form with Modal = No.

I use the Timer event to close it: TimerInterval = 200 plus this code:

Private Sub Form_Timer()
' error triggers when user clicks outside of form
On Error GoTo NotForm:

If Me.Name = Screen.ActiveForm.Name Then Exit Sub

NotForm:
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

If the user clicks outside the form, but the form record fails some
criteria (e.g., fldABC is Null), I'd like Access to cancel/prevent
whatever the user just tried to do (like opening another form), keep
the form open, and prompt him that he needs to address the missing
criteria or Cancel the record.

The use of the timer has made this all sorts of challenging, but I'd
like to keep the timer feature if possible.

I've tried all sorts of ways and can't get it working. One way is
below. It led to a disaster in which I was able to open another popup
form, which was then set Modal = True, and I had to CTL+ALT+DEL my way
out of it. But I may be going about it all wrong.

###

Private Sub Form_Timer()
On Error GoTo NotForm:
If Me.Name = Screen.ActiveForm.Name Then Exit Sub
NotForm: ' user clicked outside of form
If IsNull(Me.fldABC) Then
' Prevent user from leaving the form for executing other
events
Me.Modal = True
' Turn off timer (so msgbox doesn't keep firing)
Me.TimerInterval = 0
MsgBox "Fix date"
Else
Me.Modal = False
Me.TimerInterval = 200 ' set timer back
DoCmd.Close acForm, Me.Name, acSaveNo
End If
End If
End Sub

###

I tried also relying the BeforeUpdate event to prompt the user, but
that occurs after the TimerEvent triggers, so the form closed before
the user got the prompt to fix the issue.
 
Ad

Advertisements

D

Douglas J Steele

Put logic into the form's Unload event. If there's a condition that needs
correcting, simply set Cancel = True.


"Kurt" wrote in message

I have a popup form with Modal = No.

I use the Timer event to close it: TimerInterval = 200 plus this code:

Private Sub Form_Timer()
' error triggers when user clicks outside of form
On Error GoTo NotForm:

If Me.Name = Screen.ActiveForm.Name Then Exit Sub

NotForm:
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

If the user clicks outside the form, but the form record fails some
criteria (e.g., fldABC is Null), I'd like Access to cancel/prevent
whatever the user just tried to do (like opening another form), keep
the form open, and prompt him that he needs to address the missing
criteria or Cancel the record.

The use of the timer has made this all sorts of challenging, but I'd
like to keep the timer feature if possible.

I've tried all sorts of ways and can't get it working. One way is
below. It led to a disaster in which I was able to open another popup
form, which was then set Modal = True, and I had to CTL+ALT+DEL my way
out of it. But I may be going about it all wrong.

###

Private Sub Form_Timer()
On Error GoTo NotForm:
If Me.Name = Screen.ActiveForm.Name Then Exit Sub
NotForm: ' user clicked outside of form
If IsNull(Me.fldABC) Then
' Prevent user from leaving the form for executing other
events
Me.Modal = True
' Turn off timer (so msgbox doesn't keep firing)
Me.TimerInterval = 0
MsgBox "Fix date"
Else
Me.Modal = False
Me.TimerInterval = 200 ' set timer back
DoCmd.Close acForm, Me.Name, acSaveNo
End If
End If
End Sub

###

I tried also relying the BeforeUpdate event to prompt the user, but
that occurs after the TimerEvent triggers, so the form closed before
the user got the prompt to fix the issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top