Results 1 to 2 of 2
  1. #1
    arti is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    1

    loosing exclusivity after running code

    Hello everybody.

    I have a classmodule named “classFrmMasters” with the following code:

    ********** classmodule code **********
    Private WithEventsclsVarFrmMaster As Form
    Private WithEventsclsVarFrmSubCtrl As SubForm

    ‘routine called from the form declaring the class module
    Public SubinitFrm(frm As Form)
    Set clsVarFrmMaster = frm
    With clsVarFrmMaster
    Set clsVarFrmDataSheet =!frmSubCtrl.Form
    .OnLoad = "[Event Procedure]"
    Set clsVarFrmSubCtrl = !frmSubCtrl
    clsVarFrmSubCtrl.OnExit = "[EventProcedure]"
    End With
    End Sub

    ‘function neededto check whether the sub form already has records
    Private Function subFormHasData()As Boolean
    subFormHasData =clsVarFrmSubCtrl.Form.Recordset.EOF
    End Function

    Private SubclsVarFrmMaster_Load()
    ‘codefor the Form_Load event
    If subFormHasData=True then
    ‘dosomething
    Else
    ‘dosomething else
    End If
    End Sub

    Private SubclsVarFrmSubCtrl_Exit(Cancel As Integer)
    ‘code for the sub form “Exit”event.
    ‘……
    End Sub
    ********** end classmodule code **********


    I have severalforms each containing a sub form control. Each form has the following code:

    ********** formmodule code **********
    Option CompareDatabase
    Option Explicit

    Dim clsFrmMasterAs classFrmMasters

    Private Sub Form_Open(CancelAs Integer)
    Set clsFrmMaster = New classFrmMasters
    clsFrmMaster.initFrm Me
    End Sub

    Private SubForm_Unload(Cancel As Integer)
    Set clsFrmMaster = Nothing
    End Sub
    ********** end formmodule code **********

    The code works perfectly.The only problem is that after referring to the sub form through the “subFormHasData()”function in the class module I loose exclusivity access to the database. So,after exiting code, if I try to apply some design changes to forms or to modulesor other MS-Access objects I get an error message “You do not have exclusiveaccess to the database at this time. If you make changes, you may not be ableto save them later.".
    In order to fixthis problem I have either to close and re-open the database file, or tocompact and repair it but this is quite boring and time wasting.

    It seems that the cause is that by referring to the subform a new connection to the database isopened. I found the following routine on Microsoft Support site which determineswho is logged on to a database.

    ********** msroutine code **********
    SubShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long
    Set cn = CurrentProject.Connection

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

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

    'Output the list of all users in thecurrent database.


    Debug.Print rs.Fields(0).Name,"", rs.Fields(1).Name, _
    "", rs.Fields(2).Name,rs.Fields(3).Name
    While Not rs.EOF
    Debug.Print rs.Fields(0), rs.Fields(1),_
    rs.Fields(2), rs.Fields(3)
    rs.MoveNext
    Wend
    End Sub
    ********** end msroutine code **********

    I copied and pastedthe above routine on a module and run it before and after opening the form callingthe “classFrmMasters”.

    -Below is theoutput result of the routine BEFORE opening the form:
    COMPUTER_NAME LOGIN_NAME CONNECTED SUSPECT_STATE
    DESKTOP-L708R4V Admin True Null

    -Below is theoutput result of the routine AFTER opening the form:
    COMPUTER_NAME LOGIN_NAME CONNECTED SUSPECT_STATE
    DESKTOP-L708R4V Admin True Null
    DESKTOP-L708R4V admin True Null

    There is a newuser named “admin” (with the lower “a”) logged who now has exclusive access tothe database!

    Does anybody knowshow I could fix this problem?
    Thank you
    Arti

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I believe the code you found from MS Support is very old code for use with the LDB lock files created by MDB databases.
    If used with ACCDB databases, the user is ALWAYS reported as 'admin'
    See this example database https://www.access-programmers.co.uk...d.php?t=295174

    I realise you have deliberately edited your class module code - presumably to make the post a reasonable length
    However in doing so, its difficult to see what the purpose of the class module actually is.

    Have you tried running the code directly from the form or subform without invoking the CM?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Stop code running.
    By Homegrownandy in forum Programming
    Replies: 11
    Last Post: 05-22-2017, 02:11 PM
  2. Replies: 6
    Last Post: 05-09-2017, 10:43 AM
  3. Running code in the background
    By LostInTheTrees in forum Programming
    Replies: 3
    Last Post: 04-16-2015, 06:00 PM
  4. Form loosing link to table
    By kcm4491 in forum Forms
    Replies: 9
    Last Post: 03-23-2011, 07:27 AM
  5. Loosing list box slection after refresh
    By oakoen in forum Forms
    Replies: 6
    Last Post: 11-23-2010, 11:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums