?
Solved

ms access Inactive logout code help

Posted on 2011-04-24
7
Medium Priority
?
381 Views
Last Modified: 2012-05-11
i have a mod i am using below
Option Compare Database
Option Explicit
Public gintInactiveTimeout As Integer

Function isd_SetInactiveTimeoutVar(blnTrueOrFalse As Boolean) As Integer
'* This routine is used to set the value of the global Inactive Timeout variable
If blnTrueOrFalse = True Then
    gintInactiveTimeout = True
Else
    gintInactiveTimeout = False
End If
End Function

Open in new window


and a code i am using below on a form called "frmInactiveShutDown"

Private Sub Form_Timer()
'**********************************************************************
'* This timer event procedure will shut down the application
'* after a specified number of minutes of inactivity. Inactivity
'* is measured based on how long a control remains the ActiveControl.
'**********************************************************************
Dim sngElapsedTime As Single
Dim ctlNew As Control
Dim i As Integer
Dim FN(20) As String
On Error Resume Next

Set ctlNew = Screen.ActiveControl
If Err <> 0 Then
    '* No activecontrol
    'pddxxx need to use datediff("s" ... here because timer resets at midnight
    ' find difference in seconds
    sngElapsedTime = Timer - sngStartTime
    Err.Clear
Else
    If ctlNew.NAME = "InactiveShutDownCancel" Then
        '* The warning form has appeared, and the cancel button
        '* is the active control
        sngElapsedTime = Timer - sngStartTime
    Else
        If ctlNew.NAME = ctlSave.NAME Then
            '* Still at same control
            sngElapsedTime = Timer - sngStartTime
        Else
            '* Some change has occured, we're at a new control
            Set ctlSave = ctlNew
            sngStartTime = Timer
        End If
        If Err <> 0 Then
            Set ctlSave = Screen.ActiveControl
        End If
    End If
End If
Err.Clear

Set ctlNew = Nothing

Select Case sngElapsedTime
Case Is > (intMinutesUntilShutDown * conSeconndsPerMinute)
    '* Set global timeout variable, then shut down each form
    '* This code can be used if there is code in the form's BeforeUpdate,
    '* or OnClose event procedure that requires user input.
    '* The variable "gintInactiveTimeout" can be checked in the form events
    '* and can be used to prevent the user prompt code from executing.
    Dim frm As Form
    
    '* Set the global variable "gintInactiveTimeout" to True if the basISDOptionalModule is included
    Select Case xg_CallIfPresent("isd_SetInactiveTimeoutVar(True)")
    Case 1, 2, 3, 99
        '* We'll accept the results regardless of the return code
    Case Else
    End Select
    
    '* Close all forms
    For i = 0 To 20
        FN(i) = ""
    Next i
    i = 0
    '* Find all open form names
    For Each frm In Forms
        If i > 20 Then
            Exit For
        End If
        If frm.NAME = "frmInactiveShutDown" Then
        Else
            FN(i) = frm.NAME
            i = i + 1
        End If
    Next frm
    '* Now close them all
    For i = 0 To 20
        If FN(i) = "" Then
        Else
            'MsgBox "Closing " & FN(i)
            DoCmd.Close acForm, FN(i), acSaveYes
        End If
    Next i
    
    '* Set the global variable "gintInactiveTimeout" to False if the basISDOptionalModule is included
    Select Case xg_CallIfPresent("isd_SetInactiveTimeoutVar(False)")
    Case 1, 2, 3, 99
        '* We'll accept the results regardless of the return code
    Case Else
    End Select
    
    Set frm = Nothing
    
    Set ctlSave = Nothing
    DoCmd.Quit acQuitSaveAll
Case Is > ((intMinutesUntilShutDown - intMinutesWarningAppears) * conSeconndsPerMinute)
    '* Make the warning form visible if it is not already visible.
    If Me.Visible Then
    Else
        Me.Visible = True
        
        If conPopUpISDFormForeground Then
            '* Un-minimize Access application if it is minimized
            If IsIconic(Application.hWndAccessApp) Then
                ShowWindow Application.hWndAccessApp, SW_RESTORE
            End If
            '* Make it the foreground window - open it in front of other application windows.
            SetForegroundWindow (Me.hWnd)
        End If
        
        '* Open it on top of other modal windows.
        SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
    End If
Case Else
    '* The next line can be commented out if the form is opened hidden
    'Me.Visible = False
End Select

Exit_Section:
    On Error Resume Next
    On Error GoTo 0
End Sub

Open in new window


In the code on the form there is a line that reads
Set ctlSave = Nothing
    DoCmd.Quit acQuitSaveAll
I want instead of DoCmd.Quit i need it to DoCmd.Open acForm, "frmLogin"
the problem i am having is it keeps opening and closing that "frmLogin" so i need the code to do this  close all forms, and open frmLogin instead of quitting the app.


Below is the rests of the code on the form, might not be of any help, but its here just incase

Option Compare Database
Option Explicit
Const conPopUpISDFormForeground = True

Const conSeconndsPerMinute = 60
Dim sngStartTime As Single
Dim ctlSave As Control
Dim intMinutesUntilShutDown As Integer
Dim intMinutesWarningAppears As Integer
Private Const SW_RESTORE = 9
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
Private Declare Function SetForegroundWindow& Lib "user32" (ByVal hWnd As Long)
Private Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Function xg_CallIfPresent(pstrFunctionNameAndParms As String) As Integer
'* Call a function using the Eval function.
'* This method allows us to call a function whether it exists or not.
'*
'* Returns
'*   1 - Function found, executed, and returns True
'*   2 - Function found, executed, and returns False
'*   3 - Function not found
'*   99 - Other error

Dim intRtn As Integer

On Error Resume Next
If Eval(pstrFunctionNameAndParms) Then
    If Err <> 0 Then
        Select Case Err
        Case 2425, 2426
            intRtn = 3     '* The function is not found
        Case Else
            MsgBox "Error in xg_CallIfPresent when calling '" & pstrFunctionNameAndParms & "': " & Err.Number & " - " & Err.Description
            intRtn = 99     '* Other error
        End Select
        Err.Clear
    Else
        intRtn = 1  '* Function evaluates to True
    End If
Else
    intRtn = 2  '* Function evaluates to False
End If

Exit_Section:
    On Error Resume Next
    xg_CallIfPresent = intRtn
    On Error GoTo 0
    Exit Function
Err_Section:
    Beep
    MsgBox "Error in xg_CallIfPresent: " & Err.Number & " - " & Err.Description
    Err.Clear
    Resume Exit_Section

End Function



Private Sub Form_Close()
On Error Resume Next
ctlSave = Nothing
Err.Clear
On Error GoTo 0
End Sub

Private Sub Form_Open(CANCEL As Integer)

'* Set this variable to the number of minutes of inactivity
'* allowed before the application automatically shuts down.
intMinutesUntilShutDown = DLookup("MinutesUntilShutDown", "tblInactiveShutDown", "[TimeID]=1")
'intMinutesUntilShutDown = 120

'* Set this variable to the number of minutes that the
'* warning form will appear before the application
'* automatically shuts down.
intMinutesWarningAppears = DLookup("MinutesWarningAppears", "tblInactiveShutDown", "[TimeID]=1")
'intMinutesWarningAppears = 2

Me.Visible = False
sngStartTime = Timer
End Sub

Open in new window

0
Comment
Question by:Blueice13085
  • 4
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 35457646
If you get Peter's Forced Shutdown code http://www.peterssoftware.com/fsd.htm ... there is code in there to close All Forms .. then the app. So, instead of closing the app, comment that out and open your login form instead.

The code you need is in the sample form's Timer Event.

mx
0
 

Author Comment

by:Blueice13085
ID: 35457757
this is from that, and i sent him an email was instructed by perter to post on sites for help on this matter, thanks
0
 

Author Comment

by:Blueice13085
ID: 35457859
hm i have looked at that and i dont understand what you are talking about, i have downloaded inactive shut down from peters software codes a little but different?
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 75
ID: 35457872
The FSD has additional code to close ALL forms.  You can see how to do it ... and use that portion of the code with the code you have now.

mx
0
 

Author Comment

by:Blueice13085
ID: 35463892
that does not help  me what so ever, but i thank you for the help i will play around and try and figure it out!
0
 
LVL 75
ID: 35464104
It should because the code snippet in the Timer event does exactly what you want ... close All Forms.

mx
0
 

Author Comment

by:Blueice13085
ID: 35464283
yes i understand that so does the code that i am using it does the same thing as that code that you are speaking of i will post a new question that i have. thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question