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

x
?
Solved

VBA code works in one DB but not another

Posted on 2013-10-23
10
Medium Priority
?
372 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 300 total points
ID: 39594062
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
ID: 39594083
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
ID: 39594089
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Author Comment

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

Expert Comment

by:Jeffrey Coachman
ID: 39594111
<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
 
LVL 61

Expert Comment

by:mbizup
ID: 39594115
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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1200 total points
ID: 39594123
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
ID: 39594235
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 58
ID: 39594353
More then likely, it's pathing or security, both of which will give you that error message.

Jim.
0
 

Author Closing Comment

by:HKFuey
ID: 39605467
Thanks for the help.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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.

927 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