Probleempje met automatisch afsluiten access na inaccitviteit

Status
Niet open voor verdere reacties.

jo geuens

Gebruiker
Lid geworden
13 feb 2010
Berichten
190
hallo na wat zoekwerk heb ik deze in elkaar gestoken alleen lukt het mij niet als de melding van inactiviteit wordt weerggeven
de database af te sluiten na bv. 1 min niet bevestigd te hebben .

iemand die me hierbij kan helpen?

Bekijk bijlage automatisch afsluiten.rar
 
Laatst bewerkt:
Welk voorbeeldje heb je gebruikt? Ik ga er voor het gemak van uit dat je de procedure niet zelf bedacht hebt?
 
Je krijgt wel de msgbox, maar de rest lukt niet? Da's eigenlijk niet zo lastig.
Code:
Sub IdleTimeDetected(ExpiredMinutes)
Dim Msg As String
Dim q As Variant
    Msg = "No user activity detected in the last " & ExpiredMinutes & " minute(s)!"
    q = MsgBox(Msg, vbYesNo + vbDefaultButton2, "Afsluiten")
    If q = vbYes Then Application.Quit (acQuitSaveAll)

End Sub
 
daar had ik ook al aangedacht maar zolang je niet op ja klikt blijft de db toch openstaan en dat was nu net niet de bedoeling

deze had ik ook al eens geprobeerd en bij deze werkt dat wel maar als ik dan een wijzeging aanbreng in een formulier sluit deze de db telkens voor de tijd verstreken is
kan deze niet in een voorbeeldje steken omwille van de grote van mijn bestand

toch al bedankt voor de moeite



Code:
Option Compare Database
Option Explicit

'  Description:
'    A form that monitors user activity and automatically shuts down the application after
'    a specified period of inactivity.
'
'    Import the form frmInactiveShutDown into your application and open it hidden at application startup.
'
'    Set the inactivity period by adjusting values in the form OnOpen event procedure.
'
'    Optionally include the basISDOptionalModule to take advantage of a global variable that is set
'    to True when an Inactive Timeout occurs.
'


'* Set this constant to True if you want the ISD form to pop up in front of other
'* application windows when an Inactive Timeout occurs.
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

'v3.0 - Access 2010 64-bit compatibility
#If VBA7 Then
    Private Declare PtrSafe Function SetForegroundWindow& Lib "user32" (ByVal hwnd As LongPtr)
    Private Declare PtrSafe Function IsIconic Lib "user32" (ByVal hwnd As LongPtr) As Long
    Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
    Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
#Else
    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
#End If
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_Click()
sngStartTime = Timer
End Sub

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 = 2
'intMinutesUntilShutDown = 120

'* Set this variable to the number of minutes that the
'* warning form will appear before the application
'* automatically shuts down.
intMinutesWarningAppears = 1
'intMinutesWarningAppears = 2

Me.Visible = False
sngStartTime = Timer
End Sub

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

'If Time() > #5:00:00 PM# Then  '* Uncomment this to have ISD start at a particular time of day
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
'Else
'    sngElapsedTime = 0
'End If

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


Private Sub InactiveShutDownCancel_Click()
sngStartTime = Timer
Me.Visible = False
End Sub
 
Waarom wil je dan een msgbox? De bedoeling van een msgbox is nu juist dat je een dialoog hebt met de gebruiker, waarin die gebruiker een keus kan maken. Wil je dat niet (i.c. de gebruiker rüscksichtlos uit de db knikkeren) dan moet je een andere procedure volgen. Daarvoor gebruik ik overigen heel wat minder code...
 
hoi, moet niet echt een msgbox zijn maar gewoon een melding dat de db gaat sluiten is ook al goed zodat de gebruiker nog de tijd heeft om den bewerking te
maken zodat de timer gereset wordt en de db niet sluit

of misschien een voorbeeld van jou code
 
Je database opstarten met een timer die als event een kleine form op laat komen als "popup" met daarin een tekst "nog 5 minuten :) ", in de kleine form dmv een timer event de database laten afsluiten na pak 'm beet 5 minuten.:rolleyes:
 
Laatst bewerkt:
In de nieuwe nieuwsbrief leg ik e.e.a. piekfijn (hoop ik althans) uit, met een aantal bruikbare technieken. :)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan