ACCDE file error

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
yballanAuthor Commented:
Dear Mr. McDaniel,

Thank you for your response, I have attached the screen shot, please take a look.
screenshot reference
yballanAuthor Commented:
Sorry, I think the resolution is not good, I just attached it without embedding this time.
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

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: , item "f.".

Post back if the problem persists.
yballanAuthor Commented:
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.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
yballanAuthor Commented:
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.
yballanAuthor Commented:

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.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Is Office installed on the target machine?
yballanAuthor Commented:
No, do I need Office 2010?  
I have Office 2007 (Word, Excel).  Should I install that?
Are you opening the database file from a trusted location?
yballanAuthor Commented:
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.
yballanAuthor Commented:
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.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 "\".
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Note that the value in <my app> in Peter's suggestion above must be unique on the machine, so be aware of that.
yballanAuthor Commented:
Yes!!!!  It finally works!  Thank you both very much!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.