Go Premium for a chance to win a PS4. Enter to Win


ACCDE file error

Posted on 2013-12-28
Medium Priority
Last Modified: 2013-12-29
Dear Experts,

I have created an application using my Access 2010 (14.0.7106.5003) SP2 MSO.
Problem occurs when I create ACCDE file, then try to run it on another 32-bit machine with Access 2010 runtime environment.
The error message is
" The database cannot be opened because the VBA project contained in it cannot be read. "
and more info on how it is going to delete the VBA project, etc.
From what I looked up on Internet, this occurs with version confusion, but I am using 32-bit Access to develop and compile, and downloaded 32-bit Access 2010 Runtime to run it on the other PC, so I think I matched the version.  Clearly, I am doing something wrong.
Please advise.
Question by:yballan
  • 9
  • 5
  • 3
LVL 85
ID: 39744201
Often this is caused by mismatched references. The references you've made in your database must exist on the target machine - for example, if you have the Excel Object Library xx checked, then that will have to be installed and configured on the target machine in order for this to work correctly.

Can you perhaps list the References in your database? You can view these by opening the VBA Editor, then click Tools - References, and take a screenshot of the reference listing.

Author Comment

ID: 39744211
Dear Mr. McDaniel,

Thank you for your response, I have attached the screen shot, please take a look.
screenshot reference

Author Comment

ID: 39744215
Sorry, I think the resolution is not good, I just attached it without embedding this time.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 12

Expert Comment

ID: 39744273
First, make a backup of your database.

Remove any references that you don't need. If you can compile your database without the referenced checked, it is pretty sure that you don't need it.

Try a decompile. Details are here: http://peterssoftware.com/t_fixerr.htm , item "f.".

Post back if the problem persists.

Author Comment

ID: 39744634
Dear pdebaets,

I removed all but Visual Basic For Applications & Microsoft Access 14.0 Object Library.
When I tried to compile, I got an error on
    Dim fd As FileDialog

What disturbed me was that when I looked up FileDialog, I found this on Microsoft site:

Note The FileDialog method works only in the full retail version of Microsoft Access. This method does not work in a Microsoft Access run-time application.

Does this mean that in order to run my code, my users must purchase full retail version of Access?  I rely on this function to allow a user to pick graphics files, which is extremely important.

Thank you for your help.
LVL 85
ID: 39744660
The FileDialog is part of the Office library, so your user would need a full version of Office on the machine (not necessarily Access, however).

You can use API calls to allow the user to pick a file. API calls work with the Windows subsystem, not Office, so they'll work regardless of what's installed.


Here's the MSDN example:


I adapted the above to VBA below:
Option Compare Database
Option Explicit

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
         "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

       Private Type OPENFILENAME
         lStructSize As Long
         hwndOwner As Long
         hInstance As Long
         lpstrFilter As String
         lpstrCustomFilter As String
         nMaxCustFilter As Long
         nFilterIndex As Long
         lpstrFile As String
         nMaxFile As Long
         lpstrFileTitle As String
         nMaxFileTitle As Long
         lpstrInitialDir As String
         lpstrTitle As String
         flags As Long
         nFileOffset As Integer
         nFileExtension As Integer
         lpstrDefExt As String
         lCustData As Long
         lpfnHook As Long
         lpTemplateName As String
       End Type

Function GetFileName(OwnerHwn As Long) As String

    Dim stOpenFile As OPENFILENAME
    Dim ret As Long
    Dim sfilter As String

    With stOpenFile
        .lStructSize = Len(stOpenFile)
        .hwndOwner = OwnerHwn
        .hInstance = Application.hWndAccessApp

        sfilter = "Text files (*.txt)" & Chr(0) & "*.txt" & Chr(0)
        .lpstrFilter = sfilter
        .nFilterIndex = 1
        .nMaxFile = Len(.lpstrFile) - 1
        .lpstrInitialDir = "C:\"
        .lpstrTitle = "Choose File"

        ret = GetOpenFileName(stOpenFile)

        Dim sRet As String

        If ret <> 0 Then
            sRet = Trim(.lpstrFile)
            sRet = "Cancel"
        End If
    End With

    GetFileName = sRet
End Function

Open in new window

To use that, copy the code above into a new, standard module. Name the module something like "basFileDialog". then save it. To use it, call it like this, perhaps in the Click event of a button:

Dim sFile as String
sFile = GetFileName(Me.hWnd)

Msgbox sFile

You could adapt this so that you could pass in the initial directory, the dialog title, etc.

Author Comment

ID: 39744667
Dear Mr. McDaniel,

What a relief to hear that!!  Thank you for the detailed instructions, I will try it immediately.
After this issue is solved, I will get back to my original issue, but I am hoping that this was the root cause of it.
I will keep you posted.

Author Comment

ID: 39744748

I recompiled with the FileDialog removed, and with only 3 references:
Visual Basic For Applications
Microsoft Access 14.0 Object Library
Microsoft Office 14.0 Access database engine Object Library.

But I still get the same error message, "The database cannot be opened because the VBA project..."

Please advise.  Thank you.
LVL 85
ID: 39744773
Is Office installed on the target machine?

Author Comment

ID: 39744785
No, do I need Office 2010?  
I have Office 2007 (Word, Excel).  Should I install that?
LVL 12

Expert Comment

ID: 39744865
Are you opening the database file from a trusted location?

Author Comment

ID: 39744948
Dear pdebaets,

How can I add the folder to the trusted location with just Access runtime?
I don't see option menu when I open my application.

Author Comment

ID: 39744957
Dear Experts,

I just did a small test, I created an ACCDB file, containing a table with one field, then created a form with the field, then a button.
I wrote a blank VB script for the button, then compiled and created ACCDE.
When I try to run it on my target machine, it does not give me an error, just the security warning, but then there is no form or table.
I am getting very confused, please help.
LVL 85

Accepted Solution

Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 39744980
Have you performed maintenance on the database prior to creating the accde?

First, make a backup, then do this:

1. Compact the database
2. Compile your code. From the VBA Editor, click debug - compile. Fix any errors, and continue doing this until the menuitem is disabled.
3. Compact again.

Sometimes you need to "decompile" the code. To do that, create a shortcut wit this as the target:

"full path to msaccess.exe" "full path to your database" /decompile

Run that shortcut and then run the 3 steps above.

Finally, you may need to create a new, blank database and import everything into that database.

Also be sure that both your development and target machines are fully up to date regarding Office and Windows.
LVL 12

Assisted Solution

pdebaets earned 1000 total points
ID: 39745002
Usually you can specify that a registry key value be created on the end user's computer as a part of your database's installation - assuming you are using a software product to do the installation.

Otherwise, just go to the computer with the runtime and create the registry key using regedit.  The key to create is

Key: Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\<my app>
ValueName: Path
Value: <path>

... where "<my app>" can be anything, so it's perhaps best to use an identifier for your application, and "<path>" is the path to the folder where your .accde file resides, suffixed with a "\".
LVL 85
ID: 39745250
Note that the value in <my app> in Peter's suggestion above must be unique on the machine, so be aware of that.

Author Closing Comment

ID: 39745304
Yes!!!!  It finally works!  Thank you both very much!!!!

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question