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

How to upload a file to embed in DB???

Status
Not open for further replies.

attrofy

IS-IT--Management
Jan 10, 2002
694
US
I am trying to set up a Database for inventory, and I want to be able to have the users include a photo of the item that is inventoried.

I am not sure how to go about doing this (i.e. browsing the HD/Floppy for a file, embeding the image into a an object frame, saving the photo with theDB etc.)

Also, if I do this, will I be able to extract the photo for other purposes later on, or is it permanently embeded (like a background image)?

I appreciate any help on this topic.

Thanks, Russell
 
Is it possible to have the user dump the required image in a predefined directory? Then if you give the file a name following a specific syntax the db can automatically look for it. If it finds it then display, if not then dont do anything....

cheers
 
Benwah has a good idea. If you import the images into Access, the database size gets REALLY BIG, really fast. Best to store the path and filename to the picture in your "images" folder, than to do that. Just create a field in your employee table that has the path to each employees photo.

I also created an image called nopic.jpg (black image with the words "No picture available") and stored it in that folder. When an employee was added to the DB without a picture, I would assign that file as their image. Terry
**************************
* General Disclaimor - Please read *
**************************
Please make sure your post is in the CORRECT forum, has a descriptive title, gives as much detail to the problem as possible, and has examples of expected results. This will enable me and others to help you faster...
 
That all sounds reasonable and is do-able. ANy suggestions on how to go about doing this? Also, how do I predefine an association between picture and inventory item???

For example, we are a marine dealership. The salesman will be taking pictures with a digital camera of any boats that come in on trade. The idea is to allow them to have an ongoing list of the current used boats and prices, with pictures. We also plan on using the pics to put on our web site (since we don't host in-house) and are limited by format on how we can list used inventory, so it makes sense to keep the images seperated from the DB. The DB is set up with an auto number system. How could I associate that number with a picture schene ahead of time?

Thanks for your help,
Russell
 
Hi Russel

If you have an autonumber then you can use that as part of your file naming syntax, as this will mean each photo will have a unique filename. In the example below I am assuming you only have one photo per boat, but it easy enough to accomodate for more.

This is roughly how i would do it:

dim strPhotoPath as string
dim strPhotoType as String

strPhotoType = ".jpg"
strPhotoPath = "G:\photos\"

On Error Resume Next ' Suppresses error msg if photo doesnt exist

Me.MyPic.Picture = strPhotosPath & Me.autonumber & strImageType

End Sub

oh yeah, chuck it in the on_current event of the form you use to display the photo.

hope that helps
wah
 
I don't quite follow here....

How does the picture get associated with the correct DB entry?? Is it just atking the number of the fiel (i.e. 18.jpg) and assigning it to the corresponding 18 autonumbered entry??? And as you mentioned, if there are more than one photo, how does it associate the appropriate images with the appropriate DB entry?? Also, is the "Me.MyPic.Picture" where I insert the name of the bound pictrue box??? Thanks for your help. Sotill trying to figure this VBA thing out.

Russell
 
I don't quite follow here....

How does the picture get associated with the correct DB entry?? Is it just atking the number of the fiel (i.e. 18.jpg) and assigning it to the corresponding 18 autonumbered entry??? And as you mentioned, if there are more than one photo, how does it associate the appropriate images with the appropriate DB entry?? Also, is the "Me.MyPic.Picture" where I insert the name of the bound pictrue box??? Thanks for your help. Still trying to figure this VBA thing out.

Russell
 
okies this is the idea behind my method. Just say you have a boat, lets say a 'Noosa Shark Cat' with a DB autonumber of 17. And you have a 'Haines Hunter' with an autonumber of 78.

Each vessel in the DB can have up to three photos - side & front profiles and a misc shot.

The area you dump your photos is G:\photodump
The filename syntax for each photo is [photoprofile][DB autonumber].jpg

Thus the Shark Cat photo filnames will be:
side17.jpg
front17.jpg
misc17.jpg

and the Haines Hunter will be:
side78.jpg
front78.jpg
misc78.jpg

On the form that you want to display your photos draw three image boxes with no images.

In the on_current property event for the form insert vba code:


Private Sub Form_Current()

dim strPhotoPath as string
dim strPhotoType as String

strPhotoType = ".jpg"
strPhotoPath = "G:\photodump\"

On Error Resume Next ' Supress any error msgs

Me.ImageBoxFront.Picture = strPhotosPath & "front" & Me.autonumber & strImageType
Me.ImageBoxSide.Picture = strPhotosPath & "side" & Me.autonumber & strImageType
Me.ImageBoxMisc.Picture = strPhotosPath & "misc" & Me.autonumber & strImageType

End Sub


You may want to put it in other event properties such as onload etc.

If you have any probs let me know.
cheers
wah
 
oh yeah the line Me.ImageBoxFront.Picture means -

me = current form
ImageBoxFront = name of the Image Box control on the form
Picture = the property of the image box that tells the db where the photo is.

cheers
wah
 
ahhhh - now I understand. I forgot to mention that you need to speak slowly and use small words....

Thanks for all your help - I greatly appreciate it. I'll let you know how I make out.

Russell
 
OK, I tried all, I think I have everything right, but I am getting a "Compile error: Method or Data member not found" on the "Me.autonumber". Am I supposed to rename this?? Any thoughts???

Russell
 
Off the top of my head it means that it doesnt exist. What you need to do is refer to the name of the control.

1. look at the form in design view
2. select the required autonumber control
3. right click this control and a menu will appear. From this select 'properties'.
4. a box should appear. Select the tab 'Other'. You should now see the property 'name'.

In the coding part when you type 'me.' a list should then appear with options you can choose. This list contains control names for all the controls on the relevant form.

cheers
wah
 
I tried that. It is called ID. I have typed this in the control as ID, [ID], and I just retyped the "Me." code, and let it autofind the ID control. Still no go. Is it possible I have the wrong control for the picture box? I have tried this as both a bound, and unbound object frame. If I try it as an image, it asks me to insert a picture. I forced it with an unbound object frame to insert a new image based on a "Custom" selection. I set the new image to a .jpg file I have in my c:\photodump folder. This caused it to set the image to the selected image, for all of the files that I try to create. In other words, I have one file called front1.jpg, front2.jpg and front3.jpg. I used front1.jpg as my custom file type (since .jpg was not a choice, and I on't want tohave to convert the image to .bmp or anything first). Now all the images get set to front1.jpg, even though the ID and the text box I created describing what the picture is say they are diferent.

BTW, I checked the name, and it was still set to OLEunbond10 - thought I had changed it. THis resolved the error problem.

What am I doing wrong???

Thanks for your help.

Russell
 
Just an update, it didn't work with .BMP files either. I must have a basic flaw somewhere. Any thoughts???

Russ
 
hmmm... so what u r saying is that you have resolved the error (name of the control) but are now having problems with populating the image controls so to speak?

When you create a image control, it asks you to select an image. What I do is create a simple jpg that says 'No photo available' so when the code is run and a jpg isnt found this will be displayed.

As to why the code isnt populating the image boxes... where have you placed the code? In the 'On Load' event of the form?

Also when refering to controls on a form within VBA i find it useful to use the expression builder and copy and paste what it gives you. Expression builder should give you the correct syntax.

If all else fails and the file isnt to large, email it to me and i'll have a gander. robbb@ealing.gov.uk

Cheers
wah

 
Yes - that is what I am saying. Nor more error messages, just no picture populating.

I originally had the event in the "On Current". I have since changed it to on load. Still having the same problem.

I am going to send you the DB and see what you think is wrong. I appreciate your help.

Russell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top