Check instances of opening an add-in (accde)

jacky Perpète 41 Reputation points
2023-11-10T16:03:57.73+00:00

Hi,

In VBA, is it possible when opening an add-in (accde) to check if this add-in is already opened by another database?

I would like to perform an action in my add-in only each time it is opened for the first time.

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
823 questions
{count} votes

1 answer

Sort by: Most helpful
  1. jacky Perpète 41 Reputation points
    2023-11-18T05:36:29.7933333+00:00

    The problem with a flag is when your database shuts down inappropriately.

    Its status will remain unchanged.

    Here's a solution I just discovered using ADO's OpenSchema method for determining add-in connections.

    I added this code in a test addon.

    Here is the code:

    Private Sub cmdTest_Click()
    
    Const JET_SCHEMA_USERROSTER As String = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
    
    Dim cnc As New ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim countUser As Integer
    
    cnc.Provider = "Microsoft.ACE.OLEDB.12.0"
    cnc.Open "Data Source=" & CodeProject.FullName
    
    Set rst = cnc.OpenSchema(adSchemaProviderSpecific, , JET_SCHEMA_USERROSTER)
    
    Me.txtTest = rst.Fields(0).Name & " :" & vbCrLf & vbCrLf
    
    Do Until rst.EOF
        Me.txtTest = Me.txtTest & rst.Fields(0) & vbCrLf
        countUser = countUser + 1
        rst.MoveNext
    Loop
    
    rst.Close
    cnc.Close
    
    Me.txtTest.SetFocus
    
    End Sub
    

    You can check in the illustration the opening of 2 complements at the same time.

    The 3rd connection is that of the VBA code.

    If the database is closed improperly, there is no problem.

    User

    0 comments No comments