Share via

Link Pictures & Adding Browse Button

Anonymous
2012-06-29T12:16:09+00:00

Hello Everyone,

My job has recently decided that I need to build a database of test pictures, I've read many forums on the link pictures / putting browse button as I gather it makes the database too large with attachments.

My problem is I think I grasp the concept but I cant seem to use the code / Im not sure where im actually putting the code.

e.g imgControl.Picture = CurrentProjectPath & subforldername & Me.ImageName

Where do I put this ? does this go in the field or in a macro ?

Also for the browse to button I have this

Private Sub Explore_Click()

' Gets a filename from the filedialog control and puts it into

the

' "Filename" textbox control.

' Be sure to rename the Common Dialog Control "cd1"

On Error GoTo Err_Explore_Click

' Uncomment the next line to specify only a certain type of file

' to browse for (in your case jpeg files).

'cd1.Filter = "Text Files|*.jpg"

CD1.ShowOpen

Filename.SetFocus

Filename.Text = CD1.Filename

Exit Sub

Err_Explore_Click:

MsgBox Err.Description

Exit Sub

When i try to put this into a button it doesnt work

I know I sound like an idiot and thats because I am but I still have a job to do, so any help in this matter would be greatly appreciated.

I've attached my amazing database for reference, you will see pictures attached, these were before I knew about linking and I want the links to work like the attachments.

I'm sorry as I know this topic has been covered but I cannot seem to grasp it

(using access 2007)

ok I've found this

Private Sub Form_Current()

Dim ximg, path path = "C:\picturefolder" ximg = Me![employeenumber] Me.Photo.Picture = path & ximg & ".jpg"

End Sub

Correct the above Code whereever change required to match the foldername, employeenumber etc.

This works well for one picture per page, is there any way i can adjust this in order to have multiple images appear on one form

also would they be a way to make a button so you click it an choose the image you want to display in a certain box, like the way the attachments work?

any help massively appreciated

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-06-29T14:27:45+00:00

Yup, you're on the right track.  As it turns out, you can't use the Common Dialog control in Access 2007 unless you already have Visual Studio installed - and then it will only work on your machine.  (Sorry, I should have spotted that earlier.)

Take all the code you find on that web page between Code Start and Code End and copy it into a new Standard module.  (One you can see in the Nav pane.)  Use the sample code to prompt the user for a file location, then take what you get back in strInputFileName and assign it to the field on your form that stores the file path.

John Viescas, author

Microsoft Office Access 2010 Inside Out Microsoft Office Access 2007 Inside Out Building Microsoft Access Applications Microsoft Office Access 2003 Inside Out SQL Queries for Mere Mortals http://www.viescas.com/

(Paris, France)

Was this answer helpful?

0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-06-29T13:56:31+00:00

    Hi,

    I think I understand every thing you've explained and I now get the concept, I believe the piece I'm missing is the common dialog box as this site shows.

    http://vbadud.blogspot.co.uk/2007/06/visual-basic-common-dialog.html

    The site seems to indicate you can add one to a form pretty easy, however further search brings me to this code to add one :

    http://access.mvps.org/access/api/api0001.htm :

    Dim strFilter As StringDim strInputFileName as stringstrFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")strInputFileName = ahtCommonFileOpenSave( _                Filter:=strFilter, OpenFile:=True, _                DialogTitle:="Please select an input file...", _                Flags:=ahtOFN_HIDEREADONLY)

    Is this to be added as a module ?

    If you can tell me if im going in the right direction that would be great, if not no problem, you have helped a lot already

    Thanks a lot

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-06-29T13:03:51+00:00

    In the code above, you have:

    CD1.ShowOpen

    Filename.Value= CD1.Filename

    If the field called Filename is in your table and is intended to store the file path, then add an Image control (Cancel out of the stupid prompt to add an image directly) and set the Control Source to Filename.

    John Viescas, author

    Microsoft Office Access 2010 Inside Out Microsoft Office Access 2007 Inside Out Building Microsoft Access Applications Microsoft Office Access 2003 Inside Out SQL Queries for Mere Mortals http://www.viescas.com/

    (Paris, France)

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-06-29T12:42:52+00:00

    Hello,

    Thanks for your fast reply, I feel the only thing stopping me now is my lack of knowledge with access.

    I understand this part : If you're using 2007, the simplest way is to use a Text field to contain the path to the picture and then use an Image control.  Set the Control Source of the Image control to the text field in the Record Source

    I dont understand this part :   In your code, set the Value (not the Text) of the field to the path you get back from the open file dialog.  That should load the picture into the Image control with no further hassle.

    1. Which code should I use ?
    2. should it be put into a module ?
    3. if not where should it be put ?

    Appologies

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-06-29T12:28:56+00:00

    Greg-

    If you're using 2007, the simplest way is to use a Text field to contain the path to the picture and then use an Image control.  Set the Control Source of the Image control to the text field in the Record Source.  In your code, set the Value (not the Text) of the field to the path you get back from the open file dialog.  That should load the picture into the Image control with no further hassle.

    John Viescas, author

    Microsoft Office Access 2010 Inside Out

    Microsoft Office Access 2007 Inside Out

    Building Microsoft Access Applications

    Microsoft Office Access 2003 Inside Out

    SQL Queries for Mere Mortals

    http://www.viescas.com/

    (Paris, France)

    Was this answer helpful?

    0 comments No comments