Solved

ACCDE file error

Posted on 2013-12-28
17
1,211 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
  • 9
  • 5
  • 3
17 Comments
 
LVL 84
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, I think the resolution is not good, I just attached it without embedding this time.
Untitled.png
0
 
LVL 12

Expert Comment

by:pdebaets
Comment Utility
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
Comment Utility
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 84
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 84
Comment Utility
Is Office installed on the target machine?
0
 

Author Comment

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

Expert Comment

by:pdebaets
Comment Utility
Are you opening the database file from a trusted location?
0
 

Author Comment

by:yballan
Comment Utility
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
Comment Utility
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 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
Comment Utility
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
Comment Utility
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 84
Comment Utility
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
Comment Utility
Yes!!!!  It finally works!  Thank you both very much!!!!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now