Solved

VBA code works in one DB but not another

Posted on 2013-10-23
10
341 Views
Last Modified: 2013-10-28
I have this code on the opening of a database, it checks the version and if not up to date it downloads and runs an installer for the current version: -
        Dim Fso As New FileSystemObject
        Fso.CopyFile "\\Server\Share\Install.exe", "C:\Folder\Install.exe", True
        Shell "C:\Folder\Install.exe", vbNormalFocus
         DoCmd.Quit
            

Open in new window


This was working fine but now I get "invalid procedure call or argument"

If I just navigate to the .exe and run it works fine. If I copy the code to a fresh database it runs fine. Can anyone help?
0
Comment
Question by:HKFuey
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 100 total points
Comment Utility
Check your references.

From the vba editor:

Tools --> references

Ensure that the references checked are the same for both databases, specifically in sure that you have the Microsoft Scripting Runtime reference checked.
0
 

Author Comment

by:HKFuey
Comment Utility
Hi mbizup,

Microsoft Scripting Runtime reference is checked in both DB's. Attached screenshot is of the one not working.
References.bmp
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Alternatively, use FileCopy, which is built in and needs no references:

        FileCopy "\\Server\Share\Install.exe", "C:\Folder\Install.exe", True
        Shell "C:\Folder\Install.exe", vbNormalFocus
         DoCmd.Quit

Open in new window



Or use the fileSystemObject with late binding:

       Dim Fso As Object
       Set fso = CreateObject("Scripting.FileSystemObject")

        Fso.CopyFile "\\Server\Share\Install.exe", "C:\Folder\Install.exe", True
        Shell "C:\Folder\Install.exe", vbNormalFocus
         DoCmd.Quit

Open in new window

0
 

Author Comment

by:HKFuey
Comment Utility
The copy is working OK it is the Shell command that gives the error.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
<No Points wanted>

You should also be able to use FileCopy...
(VBA reference not needed)

    FileCopy "\\Server\Share\Install.exe", "C:\Folder\Install.exe"

But FSO has many other aspects/advantages that may be of use to you in other parts of your database
So this is just an FYI...

JeffCoachman
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 61

Expert Comment

by:mbizup
Comment Utility
The shell command itself is syntactically OK...

Is the install file attempting to overwrite your currently open database by any chance?

What happens if you rename your database (temporarily) and try to run the same code?
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 400 total points
Comment Utility
Still might be references.

Check any unchecked reference (doesn't matter which), compile, ensure no errors, then save and close DB and Access.

Re-open and uncheck the reference just checked (will be last).  Again, compile, ensure no errors, then save and close DB and Access.

Try again.   If you still get the error, then it may be pathing and/or security that is the problem.

Take that exact DB, give it to another user who does not have an issue, and try it.   If it fails there, then the DB is corrupt.  If it works, then it is pathing and/or security that is the issue for the user having the problem.

Jim.
0
 

Author Comment

by:HKFuey
Comment Utility
Re "What happens if you rename your database (temporarily) and try to run the same code?"

I get same error.

This is an old mdb that has been running for years. I tried importing everything to accdb and still get the error!
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
More then likely, it's pathing or security, both of which will give you that error message.

Jim.
0
 

Author Closing Comment

by:HKFuey
Comment Utility
Thanks for the help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

771 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

8 Experts available now in Live!

Get 1:1 Help Now