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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I add photos to my database and store them in Access?

Status
Not open for further replies.

warp9

Technical User
Jun 7, 2004
1
0
0
US
Hi, I have been looking into how I can store photos in access and then add them into reports. I've been able to do this with image files (gifs) but not jpegs or tiffs.

I actually want the photos to appear in the database as thumbnails, so when I do my research I can see them. Then I'll select the records I need and either print or fax a report.

Any assistance you can give would be greatly appreciated. Thanks, Pam.
 
i personally prefer not to embed images into the database

i put all the images in a folder and have a text field which stores the images path, then on the form have an linked image object which i set the image source to the value of the text box.

you can use a file dialog to get the imagepath or just type it in.
 
He may be a sillysod but he's right; storing photos in Access, especially multiple photos will create incredible bloat, and I expect slow down loading of Db dramatically.

The Missinglinq

"It's got to be the going,
not the getting there that's good!"
-Harry Chapin
 
missingling and sillysod are right. Don't store the images in the database - there's really no "datatype" that correctly matches any image format. Always store the path, or link, to the image file, instead. Then the field is a text datatype - small and simple.

There's always a better way. The fun is trying to find it!
 
sillysod do you have a working example?
thank you
 
warp9: Read through this thread: thread702-289543 and you will see techniques to handle your picture situation in both forms and reports.

I just posted in thread702-859576 also. I really is not necessary to embed your pictures directly into ACCESS but rather store them in a folder and then through code link the image control to the file.

Post back if you have any questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
I have tried following your instructions and have still managed to keep things from working. I created a table "lookupImage" with three fields; a key, "name" (text), and "imagePath". Next I created a form and place the two fields (name and imagePath) on via the listbox, so they should be linked to the table. Then I created an image and named it "myImage" and deleted the reference under Picture and placed the following under "On Current", "me![myImage].picture=me![imagePath]". When I go to view the form I receive and error stating "Microsoft Access can't find the macro 'me!myImage.' " If you have any idea what I'm doing wrong I would appreciate your assistance.

Thank you,
Steve
 
Do you have a textbox named ImagePath on this form. What is this listbox that you are referring to? Does the listbox have a rowsource that includes the imagepath? Please exlain.

Also, does the imagepath include the name of the actualy image or just the path to the folder?

post back with this inforamtion please.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Do you have a textbox named ImagePath on this form?

Yes, I put them on the form using the fieldlist box (I was incorrect in saying listbox) from my table titles "Images"
So, I have two text boxes on my form linked to my table.

What is this listbox that you are referring to? See above

Does the listbox have a rowsource that includes the imagepath? Please exlain. N/A


Also, does the imagepath include the name of the actualy image or just the path to the folder?

This is probably where I am going wrong. I saw instructions in post thread702-289543 that seemed to make sense.. I have to be honest and mistakenly refered to it in my earlier post.

Ok, where am I now. I followed the following instructions
"You have to have a textbox for the Path to the picture on the form. It can be visible to invisible, no matter. If invisible shrink it down small and set it off on the side of the form. Create a picture image with the Picture tool. Pick any .jpg or .bmp image from your file as the source of the picture. After the picture is placed then open up on the properties and remove the Picture property path way. We are going to update it with each new record anyway.

In the On Current event procedure of the form place the following code:

me![PictureImage].picture = me![ImagePath] "(by scriverb)

This morning at work I attempted to replicate what I tried at home and now can't even find the "On Current" field in the properties section for the image... Hope this isn't too confusing. I know if I can display a picture linked to a folder I can set up a database for viewing..

Thank you,
Steve
 
Andy,

Thanks for the great example. I have a couple questions for you.
1. Why the "#" in the txtPathToHyperlink field in your table?

2. Is it possible to refer to pictures elsewhere than the folder where the database is stored? I would like to be able to index images in seperate folders...

Thanks again!

Steve
 
sterobw: Hope this finds you with a database that is starting to work for you. To answer some of you questions, the OnCurrent event procedure is a subroutine of the Form not the image control.

Now the concept that I was describing in the above mentioned thread was trying to keep the user from having to store images all over their database and store the images path in each record. The idea here is to store the imagepath only one place as if all of the pictures are in one folder then we only need to know the path one time to that folder.

Now if each image is named with a naming convention that relates to the recordID then we don't even have to store the name of the image. We can just combine the image folder path with the record ID and ".jpg" to direct the image control as to where the picture is to be loaded from.

So if we store the image folder path in a time in the application and read that into a global variable we now can use that to direct the picture loading. When the images are saved into this folder just name them appropriately to the recordID. RecordID: A12345B Jpeg Image: A12345B.jpg

Now for each record it is an easy process to cancatenate the path, file name, and extension together and then update the image controls .Picture property.

Is any of this starting to make sense. This is effecient and doesn't require any additional storage of data. Just a little orginization of the files and a little code.

Post back if you have any further questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
andy, how are you. You form looks fine but I would add the following line of code to your Browse button so that the picture selected will populate the record immediately. Just copy/paste as the last line of code before the label.

Code:
Me!Picture.Picture = GetPathPart & Me!txtPicture

The only other thing that I would do is eliminate the need for the path to the pictures folder field: txtPathToHyperlink

I would create a table of parameters and store this pathway just one time for the database. Then create a Global variable and refer to that path in updating the .picture property of your contorl. No need to store this path in each record as it is the same for all.

Post back if you need help with that concept.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Hi you all...
sterobw
>>Why the "#" in the txtPathToHyperlink field in your table?

You have probably opened the database directly from the zip. You have to unzip the contents of the zip file to a folder.


scriverb

Thank you very much for your help.
Me!Picture.Picture = GetPathPart & Me!txtPicture did help!!!

How can i make the picture field to open the picture file when double clicked? (As happens with the OLE object).
This would eliminate the need for the hyperlink path .
 
Andy, I am not quite sure what you mean. Are you saying you want to double-click the picture object and have it open it full screen using some other editing or viewing software?

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Yes. By double clicking the picture would open the default viewer of the picture type showing the picture.
Exactly what the hyperlink field i have under the picture does!!!
 
I am not sure how to use the default program for the picture type. Will have to work on that one. But, you could ue a Shell statement to open a specific program with the picture in the object. Put this code with updates in the DoubleClick event procedure of the image control.

Code:
Dim x as variant
Dim path as string
path = "[i][red]C:\. .path to picture program \program.exe[/red][/i]" & Me.[blue][i]ImageControlName[/i][/blue].Picture
x = Shell(path)

Now there are probably better ways to perform this but this will get you buy.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Bob,

Thank you for your patience. I have the form working with the exception of showing the image. I can "browse" through the five (paths) to images in my table ( the paths show up in the ImageControl textbox). However, every time I go to the next image I receive an error stating "Microsoft Access can't find the macro 'Me!PictureImage.'

Any help would be greatly appreciated.

Steve
 
Post you code here so I may see it please. Highlight the line that the code is stopping on in the Debugger window.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top