Solved

ACCDE file error

Posted on 2013-12-28
17
1,270 Views
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.
0
Comment
Question by:yballan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 3
17 Comments
 
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.
0
 

Author Comment

by:yballan
ID: 39744211
Dear Mr. McDaniel,

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

Author Comment

by:yballan
ID: 39744215
Sorry, I think the resolution is not good, I just attached it without embedding this time.
Untitled.png
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 12

Expert Comment

by:pdebaets
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.
0
 

Author Comment

by:yballan
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.
(http://support.microsoft.com/kb/824272)

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.
0
 
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.

http://access.mvps.org/access/api/api0001.htm

Here's the MSDN example:

http://support.microsoft.com/kb/161286

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)
        Else
            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.
0
 

Author Comment

by:yballan
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.
0
 

Author Comment

by:yballan
ID: 39744748
Hello,

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.
0
 
LVL 85
ID: 39744773
Is Office installed on the target machine?
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:yballan
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.
0
 

Author Comment

by:yballan
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.
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 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.
0
 
LVL 12

Assisted Solution

by:pdebaets
pdebaets earned 250 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 "\".
0
 
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.
0
 

Author Closing Comment

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

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

632 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