add picture to access database

hello i have a simple windows app and i want a easy way to get a picture into my access databased
LVL 1
Chris JonesLead Application Web DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Hello blingtec903,

Have you looked at: http://www.ammara.com/dbpix/access.html  ?

Regards,

Patrick
0
Adel87Commented:
hi,
the above link is for Access applications. but since this question is under VB zone I'll assume that you want to add the pictures from a VB form.

you can always use an OLE field in access to store pictures but it's not advisable since it's difficult to handle later on.

what I would do is basically to add a browse button next to the field you want to store the picture in and instead of storing the image itself to the data field you just copy the picture from the path provided by the user to a folder in your application path and store only the name of the picture file in a normal text field in the database.

this method is the most widely used since you can easily back-up the images folder and because the large image size wont need to be stored in the database file itself. just imagine the size of the database file if you choose to store the image in the field as OLE object for few hundred pictures. it would be huge.

Please let me know if you need further assistance.

Regards,

0
Chris JonesLead Application Web DeveloperAuthor Commented:
can you show me an exmaple
0
Adel87Commented:
Hi,
This code should do the trick.
But first do the following :
1- create a folder called images inside your execution directory.
2- create a text box with the name : txtImage and set visible to false
3- bind the text box you just created to a text field  in your table inside the database, this field will store the file name of the image.
4- add the CommonDialog1 control by right clicking on the tool box and clicking on components and then check "Microsoft common Dialog control 6.0"
5- add an image control and name it image1
6- add a browse button with the name : cmdBrowse

Please let me know if you need further assistance.

Regards,
Private Sub cmdBrowse_Click()
Dim file As String
Dim fileTitle As String
CommonDialog1.Filter = "jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|BMP files (*.bmp)|*.BMP"
CommonDialog1.ShowOpen
 
If CommonDialog1.FileName <> "" Then
    file = CommonDialog1.FileName
    fileTitle = CommonDialog1.fileTitle
        While Dir(App.Path & "\images\" & fileTitle) <> ""
        fileTitle = "1_" & fileTitle
        Wend
    
    FileCopy file, App.Path & "\images\" & fileTitle
    txtImage.Text = fileTitle
End If
End Sub
 
Private Sub txtImage_Change()
If Dir(App.Path & "\images\" & txtImage.Text) <> "" Then
Image1.Stretch = True
Image1.Picture = LoadPicture(App.Path & "\images\" & Text1.Text)
End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris JonesLead Application Web DeveloperAuthor Commented:
Thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.