Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing a photograph in an Access Form 1

Status
Not open for further replies.

rj51cxa

Technical User
Mar 16, 2006
216
GB
I have a table which contains details of trophies and I want to add a picture to each record which can be viewed in either a form or a report. Ideally, I would like to link the record to a photo, rather than embed it, so that I can update the photos. This would also have the advantage of keeping the size of the database under control. The photos are in .jpg format as this takes up less space.

I have tried using a Command Button to create a Hyperlink. This opens the folder containing the photos, from which I can select the appropriate photo, which then opens in a new window. This is not really what I was after, so I have not pursued this line of investigation.

I really wanted to see the photo when I open the form with a particular record.

Could someone advise me if this is possible and how I can achieve it.

Best Regards
John
 
Hi--you can easily create the path that directly opens your .jpg files.

You will need to store in your table the file name. I'm guessing you already do that, or a portion of it anyhow. Maybe your trophy pictures are the same as their ID number or something that you already have stored.

Also, you should have the path to the folder stored some place (makes it easier to change later, rather than hunting for code to change). So have a table called AdminFilePaths, with one field called FilePath, and in it put the path to the folder:

C:\TrophyData\ or
\\fil-nw-16\Data\

or whatever it is.

So say you have a table called TrophyData and a field called TrophyModel and each jpg is named whatever the TrophyModel is. Or maybe you have another field with the name of the jpg file in it. You can leave the .jpg part off if it is always a jpg file.

Then in a form, you can have a button (named cmdOopenFile in my sample) that says VIEW, and in the Button's OnClick event, you can create the hyperlink path and specify the application you want to use to view the jpg file (you will have to tweak this to suit your table/field names and the application you use to view jpg files):

Code:
On Error GoTo Err_cmdOpenFile_Click


    Dim strPath, stAppName As String
    
    'Build the path to the jpg file here
    strPath = DLookup("Filepath", "AdminFilePaths") & Me.[TrophyFileName] & ".jpg"
    'Put the path of the program you want to use as a viewer here
    stAppName = "C:\Program Files\Common Files\Microsoft Shared\PhotoEd\PhotoEd.EXE "
    
    'Add double-quotes around the file name (to deal with spaces in the path)
    stAppName = stAppName & Chr(34) & strPath & Chr(34)
    
    
    Call Shell(stAppName, 1)
    
Exit_cmdOpenFile_Click:
    Exit Sub

Err_cmdOpenFile_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenFile_Click



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Thanks GingerR but what I really wanted was to have the photo displayed on the form all the time (similar to the Employees form in the Northwind Database). I have tried to modify the code from that form but have come unstuck there (see Thread 705-1436653). It would seem that it is not so easy as Microsoft make out in 210100 to which I was pointed by fneily.


 
Hi GingerR - I think I have found an easier way to display a picture using the code


Code:
Me.ImageFrame.Picture = Me.Photo

This code is invoked after I update a combo box to select the record I require. It works fine except when the photo field in the underlying table is blank (no photo available), when I receive an error message:

"Run-time error 94 - Invalid use of Null"

Is there any way I can modify this code so that the Image Frame remains blank if there is no photo?

Thanks a lot
John
 
How are ya rj51cxa . . .

Perhaps Handle/Display images in forms/database

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Thanks to both jadams 0173 and AceMan1 for your very helpful replies. The very detailed thread 702-289543 gives me what I need to know, and a whole lot more besides. It will take me a while to digest it.
Thanks to all and a very Happy Christmas.
John
 
I've been following this thread and trying to use your input, but I've been running around in circles. Need HELP please.
I have a table (contacts) with patient contact info. Each patient has episodes/visits (separate Episodes table). On the episodes form the 10 visits are separated into 10 tabs. On each tab I want to be able to load 4 or more images into an image frame by using a command button to choose the path. Currently I would have all the image paths stored in the episodes table. First of all what code do I need to choose the path and load it into a text box and then after requerying the form loads it into the image frame? Also would it be easier to create a separate images table or just keep them in the episodes table?
thanks for your help in advance.
Regards
Dennis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top