Duplicate opening of the same Access

Krava

Registered User.
Local time
Today, 10:53
Joined
Jul 13, 2005
Messages
72
Hi folks!

I have a problem I could not find in the forum, but maybe I used a wrong words in criteria.

So- does somebody know how to avoid opening the same Access instance (the same client) twice (or multiple) on the sam PC at the same time?
I need to get some checking mechanism that would not allow user to runt the same program (client) if it is already open.

Thank you in advance.

Krava
 
Where I found this I can't remember, but this what I use:

Code:
Function IsLoaded(ByVal strFormName As String) As Integer
   
   Const conObjStateClosed = 0
   Const conDesignView = 0
   If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
       If Forms(strFormName).CurrentView <> conDesignView Then
           IsLoaded = True
       End If
   End If
End Function

Simon
 
Hello, gentlemen!

Thank you for your help!

We will try and I will let you know.

With only best regards


Krava.
 
Simple Software Solutions

Code:
Function CountUsers(cn As ADODB.Connection)
    Dim rs          As ADODB.Recordset


    ' The user roster is exposed as a provider-specific schema rowset
    ' in the Jet 4.0 OLE DB provider.  You have to use a GUID to
    ' reference the schema, as provider-specific schemas are not
    ' listed in ADO's type library for schema rowsets

    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

    CountUsers = 0
    With rs
        Do Until .EOF
            CountUsers = CountUsers + 1
            .MoveNext
        Loop
    End With
     
    rs.Close
    Set rs = Nothing


End Function

I cannot take Credit for the above code however this function count the number of users currently using the application. You could set a limit of 1 to the user count and trap accordingly.

The code below is what I use to count the number of active users on in a multi user environment. This is good when you want to set the maximum number of users being able to access the appication at the same time. Even though each user has their own front end and share the back end this count the connections to the back end.

Simply change the db to refer to the current mdb.


Code:
Function CountConnectionInUse()

Dim BumsOnSeats As Integer
Dim szMaxUsers As Integer
    szMaxUsers = 15
    
    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    ' Open the connection
    With cn
      .Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=" & "J:\NTYG\Database" & "\ICATS-PMS.MDB"
    End With
    'You have to take off 1 user as you are part of the count
    BumsOnSeats = CountUsers(cn) - 1
    Set cn = Nothing
    
    If BumsOnSeats >= szMaxUsers Then
        If szMaxUsers > 1 Then
            MsgBox "There are aready " & szMaxUsers & " users logged into the application." & vbCrLf & vbCrLf & "Please wait while another user logs out before attempting to log in again.", vbExclamation + vbOKOnly, "Maximum number of concurrent users reached."
        Else
            MsgBox "There is aready 1 user logged into the application." & vbCrLf & vbCrLf & "Please wait while this user logs out before attempting to log in again.", vbExclamation + vbOKOnly, "Maximum number of concurrent users reached."
        End If
        
        End
    End If
    
        
    
   
End Function


CodeMaster::cool:
 
Hi, folks!

It took me some time but I have tried and it works fine!

Thank you very much for your great help!

Kind regards

Krava
 

Users who are viewing this thread

Back
Top Bottom