Determine if ACCDE or ACCDB

Signature

New member
Local time
Today, 02:32
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:
Whats wrong with simply testing the last few characters of currentproject.fullpath?
 
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.
 
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.
 
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.
 
Whats wrong with Allen Browne's method? It gets the result without opening the VBE unnecessarily.
 
Which Allen Browne method; you gave two links?

Chris.
 
Thanks for the idea - but .Properties("MDE") returns an error in Access 2010, not sure about Access 2007 though.
 
You have to handle the error.

The links are the some code, just the latter is a sample download.
 
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
 
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
 
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!
 
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! :)
 
Yes - you are right ! Didn't realize that this property exists only in a compiled version...

Thanks so much !
 
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:
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

Back
Top Bottom