execution of form events

sarahb845

Registered User.
Local time
Today, 05:20
Joined
Jun 19, 2002
Messages
43
Main form: frmPhoneLog
Hidden form: frmDetectIdleTime

I have seen several other posts dealing with user idle time. I went to the ms kb and found code that detects user idle time. That code has the entire database close when the max time has been reached. However, I want only my main form to close, but only if the record has a required field filled in.

In other words:
1) User opens form PhoneLog to blank record. DetectIdleTime form also opens & begins counting.
2) 10 minutes is up - msg box appears.
3) if record is incomplete, either
a) if they want to keep the record, send user back to field on
PhoneLog
b) if user wants to delete record, undo changes, close
PhoneLog form, and close DetectIdleTime form.
4) if record is complete, or no new record created, close PhoneLog form and close DetectIdleTime form.

So, here's my problem. After the msg. box appears, and the user selects YES to complete the record, the user is not sent back to the required field. Instead, both forms close, and the record is not saved.

CODE:

PhoneLog form:

Timer Interval set at 1000.

----ON LOAD----

Private Sub Form_Load()
' 1 - Forces the form to be a "blank" on open.
' THEN
' 2 - Puts cursor in the txtCallerName textbox.
' THEN
' 3 - Open the frmDetectIdleTime form (to detect user idle time)

DoCmd.GoToRecord , , acNewRec
Me.txtCallerName.SetFocus
DoCmd.OpenForm "frmDetectIdleTime", acNormal, "", "", acEdit, acHidden

End Sub


----BEFORE UPDATE----

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim stdResponse As Integer

' If Caller Name field is not filled out then give the user this message
If IsNull(Me.txtCallerName) Then
stdResponse = MsgBox("You must enter a Caller Name before continuing." _
& vbCr & vbCr & "Do you want to continue?" & vbCr & vbCr & _
"Click YES to finish completing the record, or NO to delete the record.", _
vbYesNo, "Incomplete Record")

' if the user says yes, stop the before update and return to field
If stdResponse = vbYes Then
Cancel = True
Me.txtCallerName.SetFocus
Exit Sub
' if they say no, stop the before update and undo the record
Else
Cancel = True
Me.Undo
End If
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

End Sub


----ON CLOSE----

Private Sub Form_Close()
On Error GoTo Err_Form_Close
Dim stdResponse As Integer

' If no record is created close the form.
If IsNull(Me.txtCallID) Or Me.txtCallID = 0 Then
DoCmd.Close acForm, "frmDetectIdleTime", acSaveNo
Exit Sub
End If

' If Caller Name field is not filled out then give the user this message
If IsNull(Me.txtCallerName) Then
stdResponse = MsgBox("You must enter a Caller Name before continuing." _
& vbCr & vbCr & "Do you want to continue?" & vbCr & vbCr & _
"Click YES to finish completing the record, or NO to delete the record.", _
vbYesNo, "Incomplete Record")

' if the user says yes, return them to the field, and do not close form
If stdResponse = vbYes Then
Me.txtCallerName.SetFocus
Exit Sub
'if they say no, undo the record, and close form
Else
Me.Undo
DoCmd.Close acForm, "frmDetectIdleTime", acSaveNo
End If
Else
DoCmd.Close acForm, "frmDetectIdleTime", acSaveNo
End If


Exit_Form_Close:
Exit Sub

Err_Form_Close:
MsgBox Err.Description
Resume Exit_Form_Close

End Sub



DetectIdleTime form:

' code directly from ms kb
Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for before
' running the IdleTimeDetected subroutine.

Const IDLEMINUTES = 10 ' set idle time to 10 minutes

Static PrevControlName As String
Static PrevFormName As String
Static ExpiredTime

Dim ActiveFormName As String
Dim ActiveControlName As String
Dim ExpiredMinutes

On Error Resume Next

' Get the active form and control name.
ActiveFormName = Screen.ActiveForm.Name
If Err Then
ActiveFormName = "No Active Form"
Err = 0
End If

ActiveControlName = Screen.ActiveControl.Name
If Err Then
ActiveControlName = "No Active Control"
Err = 0
End If

' Record the current active names and reset ExpiredTime if:
' 1. They have not been recorded yet (code is running
' for the first time).
' 2. The previous names are different than the current ones
' (the user has done something different during the timer
' interval).
If (PrevControlName = "") Or (PrevFormName = "") _
Or (ActiveFormName <> PrevFormName) _
Or (ActiveControlName <> PrevControlName) Then
PrevControlName = ActiveControlName
PrevFormName = ActiveFormName
ExpiredTime = 0
Else
' ...otherwise the user was idle during the time interval, so
' increment the total expired time.
ExpiredTime = ExpiredTime + Me.TimerInterval
End If

' Does the total expired time exceed the IDLEMINUTES?
ExpiredMinutes = (ExpiredTime / 1000) / 60
If ExpiredMinutes >= IDLEMINUTES Then
' ...if so, then reset the expired time to zero...
ExpiredTime = 0
' ...and call the IdleTimeDetected subroutine.
IdleTimeDetected ExpiredMinutes
End If
End Sub

----

'added the DoCmd.Close to the following code
Sub IdleTimeDetected(ExpiredMinutes)
Dim Msg As String

Msg = "No user activity detected in the last "
Msg = Msg & ExpiredMinutes & " minute(s)!"
MsgBox Msg, 48

DoCmd.Close acForm, "frmPhoneLog", acSaveNo
End Sub


----


Any ideas?
 

Users who are viewing this thread

Back
Top Bottom