Solved

add picture to access database

Posted on 2008-10-25
5
942 Views
Last Modified: 2010-04-21
hello i have a simple windows app and i want a easy way to get a picture into my access databased
0
Comment
Question by:Chris Jones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 22803884
Hello blingtec903,

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

Regards,

Patrick
0
 
LVL 2

Expert Comment

by:Adel87
ID: 22806628
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22817210
can you show me an exmaple
0
 
LVL 2

Accepted Solution

by:
Adel87 earned 500 total points
ID: 22820035
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
 
LVL 1

Author Closing Comment

by:Chris Jones
ID: 31509957
Thanks for your help
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question