Display Image on Form

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

Is it possible to display an image on the form in a Image Control box from a
hyperlink to the image in a folder? Does anyone have a suggestion/example of
how I could do this?
 
F

fredg

Is it possible to display an image on the form in a Image Control box from a
hyperlink to the image in a folder? Does anyone have a suggestion/example of
how I could do this?

If the field is an actual Hyperlink field, clicking on it will open
the picture in whatever program you have set up for that type of
picture, i.e. MSPaint, Microsoft Photo Editor, Windows Picture and Fax
Viewer, etc.

If you wish to show the picture in a control on your form then you
don't want a hyperlink field.

Place all of your pictures in the same folder on your hard drive if
you can. If not, it just requires a bit of different coding.

Let's assume all are in the same folder.

Add a Text datatype field to your table.
Name it "MyPicture".
Enter the name of the picture for each record in it, i.e.
UncleJohn.jpg, AuntMary.jpg, etc.

Add an Image control to your form to show the pictures.
When adding the Image control, the wizard will need a picture, so
navigate to any picture stored on your computer.
Save the control.
Then, re-open the Form in Design View and delete the Picture name from
the Image Control's Picture property.
Access will question it. Click Yes.

Then code the Form's Current event:
If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = "C:\PathToPicture\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

If you do NOT have all of the pictures in the same folder, then add
another field to your table, Text datatype. Name this field
"PicturePath".
Enter, for each record, the path to the folder that records picture is
in, i.e. "C:\MyPictures\FamilyFolder" (without the quotes).

Then code the form's Current event:

If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = [PicturePath] & "\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

The picture will change as you navigate from one record to the next.
 
M

mattc66 via AccessMonster.com

Thank you - Fredg, that worked great!!
Is it possible to display an image on the form in a Image Control box from a
hyperlink to the image in a folder? Does anyone have a suggestion/example of
how I could do this?

If the field is an actual Hyperlink field, clicking on it will open
the picture in whatever program you have set up for that type of
picture, i.e. MSPaint, Microsoft Photo Editor, Windows Picture and Fax
Viewer, etc.

If you wish to show the picture in a control on your form then you
don't want a hyperlink field.

Place all of your pictures in the same folder on your hard drive if
you can. If not, it just requires a bit of different coding.

Let's assume all are in the same folder.

Add a Text datatype field to your table.
Name it "MyPicture".
Enter the name of the picture for each record in it, i.e.
UncleJohn.jpg, AuntMary.jpg, etc.

Add an Image control to your form to show the pictures.
When adding the Image control, the wizard will need a picture, so
navigate to any picture stored on your computer.
Save the control.
Then, re-open the Form in Design View and delete the Picture name from
the Image Control's Picture property.
Access will question it. Click Yes.

Then code the Form's Current event:
If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = "C:\PathToPicture\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

If you do NOT have all of the pictures in the same folder, then add
another field to your table, Text datatype. Name this field
"PicturePath".
Enter, for each record, the path to the folder that records picture is
in, i.e. "C:\MyPictures\FamilyFolder" (without the quotes).

Then code the form's Current event:

If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = [PicturePath] & "\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

The picture will change as you navigate from one record to the next.
 
M

mattc66 via AccessMonster.com

How would I handle it if the image was moved? I'd like it to not display an
image. If there is a file name and path, but no image I'd like no image to
display. What happens now is it displays the image from before.
Is it possible to display an image on the form in a Image Control box from a
hyperlink to the image in a folder? Does anyone have a suggestion/example of
how I could do this?

If the field is an actual Hyperlink field, clicking on it will open
the picture in whatever program you have set up for that type of
picture, i.e. MSPaint, Microsoft Photo Editor, Windows Picture and Fax
Viewer, etc.

If you wish to show the picture in a control on your form then you
don't want a hyperlink field.

Place all of your pictures in the same folder on your hard drive if
you can. If not, it just requires a bit of different coding.

Let's assume all are in the same folder.

Add a Text datatype field to your table.
Name it "MyPicture".
Enter the name of the picture for each record in it, i.e.
UncleJohn.jpg, AuntMary.jpg, etc.

Add an Image control to your form to show the pictures.
When adding the Image control, the wizard will need a picture, so
navigate to any picture stored on your computer.
Save the control.
Then, re-open the Form in Design View and delete the Picture name from
the Image Control's Picture property.
Access will question it. Click Yes.

Then code the Form's Current event:
If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = "C:\PathToPicture\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

If you do NOT have all of the pictures in the same folder, then add
another field to your table, Text datatype. Name this field
"PicturePath".
Enter, for each record, the path to the folder that records picture is
in, i.e. "C:\MyPictures\FamilyFolder" (without the quotes).

Then code the form's Current event:

If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = [PicturePath] & "\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

The picture will change as you navigate from one record to the next.
 
F

fredg

How would I handle it if the image was moved? I'd like it to not display an
image. If there is a file name and path, but no image I'd like no image to
display. What happens now is it displays the image from before.
Is it possible to display an image on the form in a Image Control box from a
hyperlink to the image in a folder? Does anyone have a suggestion/example of
how I could do this?

If the field is an actual Hyperlink field, clicking on it will open
the picture in whatever program you have set up for that type of
picture, i.e. MSPaint, Microsoft Photo Editor, Windows Picture and Fax
Viewer, etc.

If you wish to show the picture in a control on your form then you
don't want a hyperlink field.

Place all of your pictures in the same folder on your hard drive if
you can. If not, it just requires a bit of different coding.

Let's assume all are in the same folder.

Add a Text datatype field to your table.
Name it "MyPicture".
Enter the name of the picture for each record in it, i.e.
UncleJohn.jpg, AuntMary.jpg, etc.

Add an Image control to your form to show the pictures.
When adding the Image control, the wizard will need a picture, so
navigate to any picture stored on your computer.
Save the control.
Then, re-open the Form in Design View and delete the Picture name from
the Image Control's Picture property.
Access will question it. Click Yes.

Then code the Form's Current event:
If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = "C:\PathToPicture\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

If you do NOT have all of the pictures in the same folder, then add
another field to your table, Text datatype. Name this field
"PicturePath".
Enter, for each record, the path to the folder that records picture is
in, i.e. "C:\MyPictures\FamilyFolder" (without the quotes).

Then code the form's Current event:

If IsNull(Me.[MyPicture]) then
Me.ImageControlName.Visible = False
Else
Me.ImageControlName.Picture = [PicturePath] & "\" & [MyPicture]
Me.ImageControlName.Visible = True
End If

The picture will change as you navigate from one record to the next.

I don't quite follow "If the Image has been moved".
If the image has been moved all you need do is enter the new path for
that image in the appropriate record. You will, of course, have to use
the second method I gave you where the path to each image is stored in
a second field, [PicturePath], in the table.
 
M

mattc66 via AccessMonster.com

I am suggesting that the database has a image name and path, but the actual
image was deleted or the name/path is wrong, so it no longer is a valid path
and image file name. I'd like to give a response back to the user. Something
like image not found..
How would I handle it if the image was moved? I'd like it to not display an
image. If there is a file name and path, but no image I'd like no image to
[quoted text clipped - 54 lines]
I don't quite follow "If the Image has been moved".
If the image has been moved all you need do is enter the new path for
that image in the appropriate record. You will, of course, have to use
the second method I gave you where the path to each image is stored in
a second field, [PicturePath], in the table.
 
B

Bill Smith

mattc66 via AccessMonster.com said:
I am suggesting that the database has a image name and path, but the actual
image was deleted or the name/path is wrong, so it no longer is a valid
path
and image file name. I'd like to give a response back to the user.
Something
like image not found..

Matt,
Just use the code Fred gave you and change the isNull statement to a path
with a a generic image. ie. Make a .jpg that says "no image for this file".

-Bill
 
F

fredg

I am suggesting that the database has a image name and path, but the actual
image was deleted or the name/path is wrong, so it no longer is a valid path
and image file name. I'd like to give a response back to the user. Something
like image not found..
How would I handle it if the image was moved? I'd like it to not display an
image. If there is a file name and path, but no image I'd like no image to
[quoted text clipped - 54 lines]
The picture will change as you navigate from one record to the next.

I don't quite follow "If the Image has been moved".
If the image has been moved all you need do is enter the new path for
that image in the appropriate record. You will, of course, have to use
the second method I gave you where the path to each image is stored in
a second field, [PicturePath], in the table.

Add a label, placed directly over the Image control.
Set it's caption to "No image found."

Add error handling to trap the error caused by Access not finding the
picture.
You never told us the exact code you are using, so you can incorporate
the following into your code:

Private Sub Form_Current()
On Error GoTo Err_Handler
LabelName.Visible = False
ImageName.Visible = True
ImageName.Picture = "C:\YourPath\" & Me!PictureName

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2220 Then
Me!ImageName.Visible = False
LabelName.Visible = True
End If
Resume Exit_Sub

End Sub
 

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