Determine if ACCDE or ACCDB (1 Viewer)

Signature

New member
Local time
Today, 15:58
Joined
Jul 8, 2012
Messages
6
Good morning.

I need to determine whether a user has opened an ACCDB or ACCDE version of the database. I understand that SYSCMD is the right way to do it. I've created a test function below, however, it returns 'False' in both ACCDB and ACCDE versions of the database. Any suggestions are greatly appreciated.

MsgBox "SYSCMD(SYSCMD_RUNTIME) RETURNS: " & SysCmd(SYSCMD_RUNTIME)

Thank you.
 
Last edited by a moderator:

speakers_86

Registered User.
Local time
Today, 15:58
Joined
May 17, 2007
Messages
1,919
Whats wrong with simply testing the last few characters of currentproject.fullpath?
 

Signature

New member
Local time
Today, 15:58
Joined
Jul 8, 2012
Messages
6
Already done - but a malicious user may rename ACCDE to ACCDB to circumvent the code. That is why we need to ensure that a user has opened the compiled version.

Thank you.
 

ChrisO

Registered User.
Local time
Tomorrow, 06:58
Joined
Apr 30, 2003
Messages
3,202
Try to open a standard Module in design mode and catch the error.

Code:
Option Compare Database
Option Explicit


[color=green]' In standard Module mdlTestForCompiled[/color]
Public Function IsCompiled() As Boolean

    On Error Resume Next
    DoCmd.OpenModule ModuleName:="mdlTestForCompiled"
    IsCompiled = IIf(Err.Number, True, False)
    Err.Clear
    
End Function
Chris.
 

ChrisO

Registered User.
Local time
Tomorrow, 06:58
Joined
Apr 30, 2003
Messages
3,202
A better version:-

Code:
Public Function IsCompiled() As Boolean

    Const conModuleName As String = "mdlTestForCompiled"
    
    On Error Resume Next
        Application.Echo False
            DoCmd.OpenModule ModuleName:=conModuleName
            IsCompiled = IIf(Err.Number, True, False)
            DoCmd.Close acModule, ObjectName:=conModuleName, Save:=acSaveNo
        Application.Echo True
    Err.Clear
    
End Function
Why would the user have access to both the compiled and un-compiled versions?

Chris.
 

speakers_86

Registered User.
Local time
Today, 15:58
Joined
May 17, 2007
Messages
1,919
Whats wrong with Allen Browne's method? It gets the result without opening the VBE unnecessarily.
 

ChrisO

Registered User.
Local time
Tomorrow, 06:58
Joined
Apr 30, 2003
Messages
3,202
Which Allen Browne method; you gave two links?

Chris.
 

Signature

New member
Local time
Today, 15:58
Joined
Jul 8, 2012
Messages
6
Thanks for the idea - but .Properties("MDE") returns an error in Access 2010, not sure about Access 2007 though.
 

speakers_86

Registered User.
Local time
Today, 15:58
Joined
May 17, 2007
Messages
1,919
You have to handle the error.

The links are the some code, just the latter is a sample download.
 

NigelShaw

Registered User.
Local time
Today, 20:58
Joined
Jan 11, 2008
Messages
1,564
Hi,

i'll give a more thourough check tonight but, i use the SYSCMD method on an application and it works fine. The way i use it is to check of the application is opened with with full Access or Runtime. Im pretty sure sure its something like-

Code:
If SysCmd(acSysCmdRuntime) = True Then
Your code example looks to me like it is checking for runtime. ACCDE & ACCDB can both be opened with full Access so that may be why you get the same result which is, runtime not running.

you could use the right() function to check the last 5 digits-

Code:
Dim bType As Boolean
Dim sFile As String
Dim sPath As String
 
'Get the path of the database that the user has opened
sPath = "C:\MyPath\MyDatabase.accdb"
 
'Get the file type
sFile = Right(sPath,5)
 
'Check the filetype
Select Case sFile
Case "accdb"
bType = True
'do whatever you need to do
 
Case "accde"
bType = False
'do whatever you need to do
 
End Select
You could use the Project.FilePath method to ge the filename of the one that has been opened.


HTH


Nigel
 

DrallocD

Registered User.
Local time
Today, 15:58
Joined
Jul 16, 2012
Messages
112
You could use the following which works in Access 2010:

Code:
Public Function IsACCDE()
On Error GoTo ErrorHappened
    Dim Result As Boolean
    Result = (CurrentDb.Properties("MDE") = "T")
ExitNow:
    IsACCDE = Result
    Exit Function
ErrorHappened:
    Resume ExitNow
End Function
 

speakers_86

Registered User.
Local time
Today, 15:58
Joined
May 17, 2007
Messages
1,919
That's what I was pointing to with Allen Brown's site.
 

Signature

New member
Local time
Today, 15:58
Joined
Jul 8, 2012
Messages
6
Unfortunately, this does not work in 2010 or 2007 - there is no such property, so function resumes on error without returning a result.

Thanks for trying anyway!
 

DrallocD

Registered User.
Local time
Today, 15:58
Joined
Jul 16, 2012
Messages
112
I use it in 2010 and it works. The property only exists in the ACCDE, in the ACCDB this generates an error which the function handles. Try it and you might be surprised! :)
 

Signature

New member
Local time
Today, 15:58
Joined
Jul 8, 2012
Messages
6
Yes - you are right ! Didn't realize that this property exists only in a compiled version...

Thanks so much !
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:58
Joined
Jul 9, 2003
Messages
11,026
I'm not a stickler for following the rules however one rule is "Not to Use Errors as part of your Code". For some reason this rule is important to me, and I prefer not to use "triggering an error" as an intrinsic part of my code. I do acknowledge that there maybe circumstances where you have no choice other than to use an Error.

Before you do, consider this method:-

Code:
Private Sub btnYourButtonName_Click()

Dim prop As Property
Dim intCounter As Integer

    For Each prop In CurrentDb.Properties
        If prop.Name = "MDE" Then intCounter = intCounter + 1
    Next prop

        If intCounter > 0 Then
            MsgBox " >>> " & " IS MDE   "
        Else
            MsgBox " >>> " & " NOT MDE   "
        End If

End Sub
This also demonstrates a principle which I have found worth knowing. If you try and examine a property, an object, something like that, and the object is not set, or the wrong type, then this can cause errors. However if you look at the objects "Name" in other words check to see if the object you want to interrogate is in the collection, then you can avoid triggering error code. In other words if an object does not exist and you try and use it then you get an error, however if you check to see if the object is named in the collection you are only examining a text property and you don't generate an error. You just look to see if the object you require is there or not...
 
Last edited:

The_Doc_Man

Happy Retired Curmudgeon
Local time
Today, 14:58
Joined
Feb 28, 2001
Messages
16,241
Then there is another way of looking at it. If you have users who get this malicious, put code in the OnOpen event of your forms (or just the switchboard form) such that if the user has renamed the file to something other than .ACCDB or .ACCDE just do a Cancel on the attempt to open the form.

This presumes that you have taken steps to secure the database, and it also does nothing for purely malicious users who somehow bypass every safeguard. But if you have any users like that and your management thinks the database function is important, ask them to "counsel" the miscreant. Offer to provide them with the nail-spiked 2x4 "attention stick" if necessary. Sometimes the problem isn't technology but education.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom