Error trapping shows 2 times message for user (1 Viewer)

BertB

New member
Local time
Today, 17:03
Joined
Jan 22, 2022
Messages
1
Hello Forum!

I am trying to create an error handling for a split database at my work.

As you know, Access has a bug since the December update. When a second user logs in, it fails.
When starting the database, a hidden form is started that allows to register a username and date/time in the tblUserlog. When the backend is already locked, the username and date/time cannot be written to the tblUserlog. To deal with the resulting error message, I want to show the user a message that the database is already in use and then close it. I have created the following procedure for this purpose.

Code:
Function LogOn()
On Error GoTo err_ErrorhandlerLogOn

    Dim sUser As String
    Dim sSQL As String
   
    DoCmd.SetWarnings False
    sUser = Environ("username")
    sSQL = "INSERT INTO tblUserLog ( UserID )" _
        & "SELECT '" & sUser & "' AS [User];"
    DoCmd.RunSQL sSQL
    DoCmd.SetWarnings True

Exit_MAA:
    Exit Function

err_ErrorhandlerLogOn:
    MsgBox "Unfortunately you cannot log in now. The database backend is already in use by another user or it is blocked for use." & vbCrLf _
            & "" & vbCrLf _
            & "Please try again later. The database will be shut down." & vbCrLf _
            & "", vbOKOnly Or vbCritical, "Beste gebruiker ..."
    Call DatabaseClose
    Resume Exit_MAA

End Function

Code:
Private sub DatabaseClose()
Application.Quit acQuitSaveNone
End sub

It works, but after closing the database, the message is displayed again. I don't understand what I'm doing wrong. Can someone help me with this?

Thanks for reading!

Kind regards, Bert
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:03
Joined
Feb 28, 2001
Messages
27,005
You are saying that you see the message from your MsgBox call twice? If I understand the way error traps work, the only way that can occur is if you get to your label err_ErrorhandlerLogin twice through two traps. A trap cannot trap itself (because at the time of the trap, the trap handler is active and Access has a way of knowing that.) It has to leave that handler through a Resume statement before the trap would reset.

The ONLY thing I would do differently there is that the Call DatabaseClose MAYBE shouldn't be inside an error handler but rather you should Resume to a label that THEN calls your DatabaseClose code before exiting the function. But I am not certain about the implied fine point of calling code subroutines from event handler context causing a repeat of a message box.

I tried a couple of searches on the topic, but so far nothing jumps out at me. On the other hand, that behavior of "exclusive use" has been seen recently due to a Windows patch-related bug and there are some articles here on how to fix that problem. Try this link....

 

GPGeorge

Grover Park George
Local time
Today, 09:03
Joined
Nov 25, 2004
Messages
1,776
Depending on which version of Access you have, the fix may already be available. IIRC, three versions are listed as having the fix pending. Check the link in post #2 for details. That's the most current and comprehensive summary available.
 

Cronk

Registered User.
Local time
Tomorrow, 03:03
Joined
Jul 4, 2013
Messages
2,770
As you know, Access has a bug since the December update. When a second user logs in, it fails.
Not exactly. Microsoft released a server security patch which had the unintended affect on Access databases of allowing only one user read/write. A fix was released on January 14.

Rather than proceeding with your alert, have IT implement the fix. Note that to be effective, you need to change any links to data from mapped drives to UNC references.
 

Users who are viewing this thread

Top Bottom