open picture from on click

G

Guest

Hi

I followed the code done in this post but I'm getting an error message... I
did the following:
1) Added a field in my table, text field, where I placed the filename of my
jpg
2) Added an unbound object frame on my form to display the jpg image and
added the "on click" code below
3) On the form where I placed my unbound object frame, I added the "on
current" code below.
4) Changed the path_name to where I stored my jpg images

Please help...


The simplest way to open just about any document in its default program
is to use something like this:

Application.FollowHyperlink Me.Path_Name & Me.Photo_Name & ".jpg"



In a form I am pulling photos using the following code.

Private Sub Form_Current()
Dim Path_Name As String
Path_Name = "P:\PR40362\Database Photos\"
On Error Resume Next
imgPicture1.Visible = True
imgPicture1.Picture = [Path_Name] & [Photo_Name] & ".jpg"
'Error message to display if photo not defined
If Err = 2220 Then
imgPicture1.Visible = False
Exit Sub
End If
End Sub

where Photo_Name is a column in the necessary table. Therefore each record
pulls a new photo. What I would like to do is "On Click" have this image act
like a hyperlink and open the image in Microsoft Picture Manager (or whatever
the defualt photo editor is set to). Thanks in advance for any help or
suggestions,

Cioffredi
 
G

Guest

Freeda:

Firstly you should use an Image control not an unbound object frame.
Secondly I would not hard-code the path to the folder in the code. The path
is data and data should only be stored as values at column positions in rows
in tables. So create a one-row table ImageFolder say with a text column
ImagePath and store the path in that. Any time you might change the location
all you need to do is edit this one-row table.

Base your form on a query which includes the table containing the names of
the JPEGs and the ImageFolder table, but do not join the tables. This will
return what's known as the Cartesian product of the tables, which joins every
row of one table to every row of the other. As Image folder only has one row
the ImagePath value will be the same in every row returned by the query.

In the form's Current event procedure you can now assign the path to the
Image control's Picture property:

Dim strFullPath as String

strFullPath = Me.ImagePath & Me.Photo_Name & ".jpg"

' if file doesn't exist exist hide control
If Dir(strFullPath) = "" Then
imgPicture1.Visible = False
Else
' show control and load image
imgPicture1.Visible = True
imgPicture1.Picture = strFullPath
End If

With JPEGs you get a progress message popping up as the file loads. This is
at best annoying, at worst can crash Access if you page too fast through the
records in the form. You can suppress it with the following registry hack:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Graphics
Filters\Import\JPEG\Options]

"ShowProgressDialog"="No"

For a method of suppressing the dialogue by calling the Windows API see the
following link:

http://www.mvps.org/access/api/api0038.htm

Ken Sheridan
Stafford, England

Freeda said:
Hi

I followed the code done in this post but I'm getting an error message... I
did the following:
1) Added a field in my table, text field, where I placed the filename of my
jpg
2) Added an unbound object frame on my form to display the jpg image and
added the "on click" code below
3) On the form where I placed my unbound object frame, I added the "on
current" code below.
4) Changed the path_name to where I stored my jpg images

Please help...


The simplest way to open just about any document in its default program
is to use something like this:

Application.FollowHyperlink Me.Path_Name & Me.Photo_Name & ".jpg"



In a form I am pulling photos using the following code.

Private Sub Form_Current()
Dim Path_Name As String
Path_Name = "P:\PR40362\Database Photos\"
On Error Resume Next
imgPicture1.Visible = True
imgPicture1.Picture = [Path_Name] & [Photo_Name] & ".jpg"
'Error message to display if photo not defined
If Err = 2220 Then
imgPicture1.Visible = False
Exit Sub
End If
End Sub

where Photo_Name is a column in the necessary table. Therefore each record
pulls a new photo. What I would like to do is "On Click" have this image act
like a hyperlink and open the image in Microsoft Picture Manager (or whatever
the defualt photo editor is set to). Thanks in advance for any help or
suggestions,

Cioffredi
 
G

Guest

Hi Ken

My query is really an "enhancement" to my existing database. I already have
a form (frmLenders) that links to a table (tblMasterLender). I just want to
add that Image Control to display the jpg image in my frmLenders. I already
added the ImagePath field to tblMasterLender. I changed my unbound object
frame to an image but it doesn't change the jpg image displayed when I click
Freeda:

Firstly you should use an Image control not an unbound object frame.
Secondly I would not hard-code the path to the folder in the code. The path
is data and data should only be stored as values at column positions in rows
in tables. So create a one-row table ImageFolder say with a text column
ImagePath and store the path in that. Any time you might change the location
all you need to do is edit this one-row table.

Base your form on a query which includes the table containing the names of
the JPEGs and the ImageFolder table, but do not join the tables. This will
return what's known as the Cartesian product of the tables, which joins every
row of one table to every row of the other. As Image folder only has one row
the ImagePath value will be the same in every row returned by the query.

In the form's Current event procedure you can now assign the path to the
Image control's Picture property:

Dim strFullPath as String

strFullPath = Me.ImagePath & Me.Photo_Name & ".jpg"

' if file doesn't exist exist hide control
If Dir(strFullPath) = "" Then
imgPicture1.Visible = False
Else
' show control and load image
imgPicture1.Visible = True
imgPicture1.Picture = strFullPath
End If

With JPEGs you get a progress message popping up as the file loads. This is
at best annoying, at worst can crash Access if you page too fast through the
records in the form. You can suppress it with the following registry hack:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Graphics
Filters\Import\JPEG\Options]

"ShowProgressDialog"="No"

For a method of suppressing the dialogue by calling the Windows API see the
following link:

http://www.mvps.org/access/api/api0038.htm

Ken Sheridan
Stafford, England

Freeda said:
Hi

I followed the code done in this post but I'm getting an error message... I
did the following:
1) Added a field in my table, text field, where I placed the filename of my
jpg
2) Added an unbound object frame on my form to display the jpg image and
added the "on click" code below
3) On the form where I placed my unbound object frame, I added the "on
current" code below.
4) Changed the path_name to where I stored my jpg images

Please help...


The simplest way to open just about any document in its default program
is to use something like this:

Application.FollowHyperlink Me.Path_Name & Me.Photo_Name & ".jpg"



In a form I am pulling photos using the following code.

Private Sub Form_Current()
Dim Path_Name As String
Path_Name = "P:\PR40362\Database Photos\"
On Error Resume Next
imgPicture1.Visible = True
imgPicture1.Picture = [Path_Name] & [Photo_Name] & ".jpg"
'Error message to display if photo not defined
If Err = 2220 Then
imgPicture1.Visible = False
Exit Sub
End If
End Sub

where Photo_Name is a column in the necessary table. Therefore each record
pulls a new photo. What I would like to do is "On Click" have this image act
like a hyperlink and open the image in Microsoft Picture Manager (or whatever
the defualt photo editor is set to). Thanks in advance for any help or
suggestions,

Cioffredi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top