Problem launching Paintbrush from code using SHELL (1 Viewer)

Essendon

Registered User.
Local time
Today, 14:39
Joined
Oct 25, 2001
Messages
65
I have a database with images stored externally (with only the paths stored in the database). I want to create a button that would open a picture with the user's default picture viewer (eg. Ms Photo Editor, Ms Paint, Photoshop etc.).

Is there anyway that I can simulate the double click of a jpg file in windows from within my program (so that it would open it with the default viewer). If not, I would just like to make it open with mspaint.

I have tried fiddling around with the shell command to get it to open with paintbrush:

Call Shell(("C:\WINDOWS\System32\mspaint.exe C:\database\images\a picture.jpg"), vbMaximizedFocus)

for some reason, as soon as you have a space in the path (like "a picture", or "C:\documents and settings" etc) Paintbrush returns an error becuase it doesn't like the space. If I change the code to open photoshop instead it works fine with the space. The trouble is that I have to get it working with paintbrush if nothing else. Any ideas?

Thanks very much,

Peter
 

Benny Wong

Registered User.
Local time
Today, 06:39
Joined
Jun 19, 2002
Messages
65
MSPAINT.EXE

Hi Essendon


Try this code on the on-click event of the button.

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Call Shell("C:\Program Files\Accessories\MSPAINT.EXE", 1)

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Hope this helps you.
 

Essendon

Registered User.
Local time
Today, 14:39
Joined
Oct 25, 2001
Messages
65
I am using windows xp. I don't have a c:\program files\accessories\ directory. I have no problems opening paint. I just cannot open any file that has a space in its path.
 

Tim K.

Registered User.
Local time
Today, 14:39
Joined
Aug 1, 2002
Messages
242
Try this out.

Dim strAppName As String
strAppName = "C:\WINDOWS\System32\mspaint.exe " & Chr(34) & "C:\database\images\a picture.jpg" & Chr(34)
Call Shell(strAppName, vbMaximizedFocus)
 

Fornatian

Dim Person
Local time
Today, 14:39
Joined
Sep 1, 2000
Messages
1,396
You could also use :

Application.FollowHyperlink "MyFilePath"

This should start up the default picture browser. Note that it may not always be editable because you can choose IE as the default viewer.
 

Essendon

Registered User.
Local time
Today, 14:39
Joined
Oct 25, 2001
Messages
65
Thanks very much

Works perfectly - thanks very much.

Whats the easiest way of finding out what char(34) is and what all the other char(x)'s are? I assume that char(34) is ".

Thanks again.
 

Users who are viewing this thread

Top Bottom