By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

ShellExecute API

P: n/a
Hi,

I have an access database form with an image. I'm trying to create an
onclick event on the image so that when a user clicks on the image it opens
that file with the default viewer the computer is set on. I've searched the
web and nothing solid. I did get the following VBA code and it doesn't seem
to work. If anyone can help me i'd appreciate it. From the code below
txtImageNote is a field on the form that displays the path to the image with
is working properly.

=====BEGIN=====
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String,
ByVal nShowCmd As Long) As Long
Private Sub imageFrame_Click()
Dim strImageName As String

strImageName = Me!txtImageNote
ShellExecute 0, vbNullString, strImageName, vbNullString, vbNullString,
vbNormalFocus
End Sub
=====END======
Jan 30 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jan 30, 8:52 am, "John Smith" <some...@microsoft.comwrote:
Hi,

I have an access database form with an image. I'm trying to create an
onclick event on the image so that when a user clicks on the image it opens
that file with the default viewer the computer is set on. I've searched the
web and nothing solid. I did get the following VBA code and it doesn't seem
to work. If anyone can help me i'd appreciate it. From the code below
txtImageNote is a field on the form that displays the path to the image with
is working properly.

=====BEGIN=====
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String,
ByVal nShowCmd As Long) As Long

Private Sub imageFrame_Click()
Dim strImageName As String

strImageName = Me!txtImageNote
ShellExecute 0, vbNullString, strImageName, vbNullString, vbNullString,
vbNormalFocus
End Sub
=====END======
This works for me:

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String,
ByVal lpFile As String, ByVal lpParameters As String, ByVal
lpDirectory As String, ByVal nShowCmd As Long) As Long
----
ShellExecute 0&, vbNullString, sPath, vbNullString, vbNullString,
vbNormalFocus
----
....where sPath is a full valid path to a file.
Jan 30 '08 #2

P: n/a
Thank you... worked great!!!

"JohnH" <Jo**********@gmail.comwrote in message
news:59**********************************@1g2000hs l.googlegroups.com...
On Jan 30, 8:52 am, "John Smith" <some...@microsoft.comwrote:
>Hi,

I have an access database form with an image. I'm trying to create an
onclick event on the image so that when a user clicks on the image it
opens
that file with the default viewer the computer is set on. I've searched
the
web and nothing solid. I did get the following VBA code and it doesn't
seem
to work. If anyone can help me i'd appreciate it. From the code below
txtImageNote is a field on the form that displays the path to the image
with
is working properly.

=====BEGIN=====
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As
String,
ByVal nShowCmd As Long) As Long

Private Sub imageFrame_Click()
Dim strImageName As String

strImageName = Me!txtImageNote
ShellExecute 0, vbNullString, strImageName, vbNullString,
vbNullString,
vbNormalFocus
End Sub
=====END======

This works for me:

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String,
ByVal lpFile As String, ByVal lpParameters As String, ByVal
lpDirectory As String, ByVal nShowCmd As Long) As Long
----
ShellExecute 0&, vbNullString, sPath, vbNullString, vbNullString,
vbNormalFocus
----
...where sPath is a full valid path to a file.

Jan 30 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.