Solved

Shell String

Posted on 2002-04-07
9
297 Views
Last Modified: 2012-06-22
I am attempting to poll through a number of network mappings and perform copy and rename command line executions from within a Shell statement.  I can't seem to get the syntax correct.  Keep getting a Cannot fine the file error.

Dim vShellString as string
Dim x as variant

vShellString = "Rename c:\access\filename.mdb filename-final.mdb"
x = Shell(vShellString)

If I execute the exact characters in a MSDOS i.e. Rename . . . .mdb  as stated above it works fine.  But, by putting it into a string there must be a syntax problem with quotes, etc. that it does not recognize the path that is being described.  I have tried cancatenating chr(34) on both ends of the string, around the actual path only, chr(39) around the path only, etc.

Can't seem to get it to work.  

Ideas experts.

Bob Scriver
0
Comment
Question by:Bob Scriver
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:xSinbad
ID: 6924236
Try ading the full path to rename.exe
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924239
xSinBad:
I don't understand what you mean by your comment.  Please elaborate.

Bob Scriver
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924278
I have resolved this question myself.  The shell statement requires a reference to the command file ( i.e. cmd /c ) within the shell string.

It should look like this:

vShellString = "cmd /c Rename c:\access\filename.mdb filename-final.mdb"

The shell statement must reference the command file to know what to do with the Reserved Command word Rename, Copy, etc.  

I will ask CS to reduce the points to 0 but I will leave this question active for others to benefit from this finding.

Bob Scriver
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 9

Expert Comment

by:ornicar
ID: 6924333
Just note that you can rename a file without invoking the DOS command. Simply:

Name [SourceFile], [DestFile]

Will do the job fine with no splashing DOS window.

You can even trap the error:

On Error Resume Next

Name [SourceFile], [DestFile]
if err <> 0 then
    msgbox "Error on renaming file: ", Error$
endif
On Error Goto 0
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924375
Ornicar:

Please be more specific because I can only find Name as a property and not in the command type format that you suggest.

Bob
0
 
LVL 9

Accepted Solution

by:
ornicar earned 50 total points
ID: 6924378
Name is also a file command, The exact command is:

NAME "c:\access\filename.mdb" AS "c:\access\filename-final.mdb"

I forgott the AS. My fault.
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924468
Ornicar:
Thanks for the follow-up to this question.  Although the original question had to do with the format of the Shell string you have given me a better way of manipulating the files with the Name command.  Also, the FileCopy and Kill commands give me everything that I need.  so I am going to award you the points for this question and with draw my request to CS to reduce the points to 0.  

Bob Scriver
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924469
Your comment is exactly what was needed to finish off my application.  Thanks

Bob scriver
0
 
LVL 9

Expert Comment

by:ornicar
ID: 6924822
You are welcome
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

770 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