Shell() with multiple parameters

Bobsan

New member
Local time
Today, 05:07
Joined
May 31, 2011
Messages
1
Hello All,

I'm fairly new to VBA (Access 2007/10) and have run into a very frustrating problem with trying to run a command-line executable with a couple of arguments.

What is supposed to happen is that after a user attaches an image file, VBA should run an exe file (jhead) in the command line, with the image.filename as the first parameter, and a temporary txt file as the output of the exe file. VBA then parses the text file to retrieve the data embedded in the image file- but this section works ok.

I can run the exe file through the command line with the right parameters and there's no problem, it outputs to the txt file as it's supposed to. But when VBA runs the same command, jhead appears to run, but does not create the text document. I've tried using Shell() as well as ShellExecute(), although I don't understand ShellExecute very well.

Code is below- watching the value of JHead shows that the string is being put together properly, with the adress of the exe, the image (that gets passed to jhead), and the output file. I can copy and paste the string into a command prompt and it works. The commented-out RetVal =... line should do the same as the previous line.

So why doesn't it work in VBA?! :eek:

Thanks in advance,

Bobsan

Code:
Private Sub Image_AfterUpdate()                                             'After attaching an Image to the form,
Dim Coords As String
Dim LatS As String, LonS As String
Dim RetVal
Dim JHead As String, OpenApp As String

OpenApp = "C:\Workspace\Kit\Image\jhead.exe C:\Workspace\Kit\Image\" & Image.FileName & " > C:\Workspace\Kit\Image\tmp.txt"
JHead = OpenApp

'RetVal = Shell(JHead, vbNormalFocus)                                       'Runs JHead.exe to pull the tags from the image and outputs to a text file
RetVal = Shell("C:\Workspace\Kit\Image\jhead.exe" & " C:\Workspace\Kit\Image\" & Image.FileName & " " & ">" & " " & "c:\Workspace\Kit\Image\tmp.txt", vbNormalFocus)


'*****************************************
Dim oFSO As New FileSystemObject                                            'Creates a filesystemobject to hold the text file
Dim oFS
Set oFS = oFSO.OpenTextFile("c:\Workspace\Kit\Image\tmp.txt")               'Opens up the file
Do Until oFS.AtEndOfStream
sText = oFS.ReadLine
sText = oFS.ReadLine
sText = oFS.ReadLine
sText = oFS.ReadLine
Coords = oFS.ReadLine                                                       'Reads out the last line to a variable
sText = oFS.ReadLine
Loop
oFS.Close                                                                   'And closes the file again
'****************************************

CoordNums = ParseWord(Coords, -1, ":")                                           'Takes the last statement from the file (coordinates from comment field)
If (CoordNums <> Null) Then
    LonS = ParseWord(CoordNums, -1, ",")                                             'Pulls the last word in as the Longitude
    LatS = ParseWord(CoordNums, -2, ",")                                             'And the 2nd-last word in as the Latitude
    Latitude = LatS
    Longitude = LonS
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom