?
Solved

VB6 Run-time error '5' when calling shell

Posted on 2014-02-14
14
Medium Priority
?
1,108 Views
Last Modified: 2014-02-17
I get this error from VB6 when calling this line:

Run-time error '5'

GetApp = Shell(App.Path & "\updateapp.bat", vbNormalNoFocus)

I do not see any setfocus in my code that I usually see through this error. This code does work by the way in a clean project with noting else.

Any suggestions?
0
Comment
Question by:mossmis
[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
  • 2
  • 2
  • +2
14 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39859646
What do you mean by:
This code does work by the way in a clean project with noting else.
How is your current setup not clean?
0
 
LVL 5

Expert Comment

by:advfinance
ID: 39859714
Does your App.Path contain spaces?

--
Chris
0
 

Author Comment

by:mossmis
ID: 39859840
Chris, the app.path does contain spaces. But this works when I isolate the code in a new project with just that command. I'm not sure what else might be causing the error.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39859847
Can you post the code (at least the full subroutine which has the offending line in it)?
0
 

Author Comment

by:mossmis
ID: 39859923
Public Sub UpdateCurrentApp()
'If the App version doesn't match automatically update the app

Dim fso As New FileSystemObject
    If Not fso.FileExists(App.Path & "\updateapp.bat") Then
        fso.CreateTextFile "updateapp.bat"
    End If

    Open App.Path & "\errors.txt" For Output As #1
    Print #1, "ECHO Please Wait.....Automatically Updating to New Version"
    Print #1, "Timeout 5"
    Print #1, "%~d1"
    Print #1, "cd ""%~p1"""
    Print #1, "copy /y """; UpdateAppFolder; UpdateAppEXE; """"; " "; UpdateAppEXE
    Print #1, "Timeout 1"
    Print #1, "start "; UpdateAppEXE
    Print #1, "exit"
    Close #1
    
    GetApp = Shell(App.Path & "\updateapp.bat", vbNormalNoFocus)
    
    End

End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:aikimark
ID: 39859943
Quote-delimit the path/filename:
GetApp = Shell(Chr(34) & App.Path & "\updateapp.bat" & Chr(34), vbNormalNoFocus)

Open in new window

0
 
LVL 12

Accepted Solution

by:
jkaios earned 2000 total points
ID: 39862167
@author (mossmis)
  should line 9 in your code reference "updateapp.bat" instead of "errors.txt" ?

  line 6: fso.CreateTextFile "updateapp.bat" does NOT match
  line 20: App.Path & "\updateapp.bat"

============ edited by aikimark
0
 
LVL 46

Expert Comment

by:aikimark
ID: 39862770

@aikmark
  actually, it should be Chr(32), which is the character code for a SPACE and not Chr(34), which is the character code for a double quote (")
No.  You should use a quote delimiter.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39863303
No.  You should use a quote delimiter.

Yes, that's right.  My bad.  I forgot that referencing a directory that has space in it must be enclosed by double quotes.
0
 

Author Comment

by:mossmis
ID: 39864837
Son of a........... line 9 had a bad file name (I copied code from another project of mine). That little thing fixed it. I didn't need to add extra quotes; I took care of it in line 14.

Thanks for catching that mistake.
0
 

Author Comment

by:mossmis
ID: 39864881
jkaios caught my mistake. Why isn't he getting the points?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

764 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