Solved

VBA code works in one DB but not another

Posted on 2013-10-23
10
366 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
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 100 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

631 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