Results 1 to 6 of 6
  1. #1
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67

    How to display a picture in a form

    I’m trying to figure out how to get a form to display a picture from a file. I have created a form, “Form1”, and on this form I place an image control, “Image4”
    My program, in Mod1, has a global variable “PictureFileName$”
    In the directory from which the database was launched, I have a jpeg file “Picture1.jpg”

    Sub DisplayForm1(PictureFile As String)
    PictureFileName$ = PictureFile
    DoCmd.OpenForm "Form1"
    End Sub

    Below is the sub which runs when Form1 is loaded

    Private Sub Form_Load()
    Dim S$
    S$ = CurrentProject.Path & "\" & PictureFileName$
    'What code would go here to make here to make control "Image4" display


    ' the jpeg file with the name PictureFileName$
    End Sub

    Can anyone show me the code which should go into the above sub so that when I run the following

    Sub Test1
    DisplayForm1 “Picture1.jpg”
    End sub

    I will see Form1 with Picture1 showing in control Image4?

    Thank you in advance.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    No code required. Set the ControlSource property:

    =CurrentProject.Path & "\PictureFileName.jpg"

    This assumes you want the same picture for every record. If you want dynamic picture then save the picture name into a text field.

    =CurrentProject.Path & "\" & [field name]
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    June, is there a way to tell the controlsource to look at the code? Or leave the properties field blank and do a form background image on the oncurrent process? I have a sizable userbase and I would like to be able to have a folder on the shared drive with a bunch of background images. Then depending on the day, choose a different image. Something to keep it funky for the bunch you know.

    Right now I just have the network path, and when I want to change the picture I swap it on the shared drive. I think it would be really nice to but some vba behind it.

    I found http://www.pcreview.co.uk/forums/wri...-t3869421.html and it seems like it would work, but thats just for punching in color codes, I wonder if it is switchable with file locatons.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Yes, the ControlSource can call a function that would return an image path/name.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Quote Originally Posted by June7 View Post
    Yes, the ControlSource can call a function that would return an image path/name.
    Awesome, well I am going to stack up a handful of background images and finish this up. I'm thinking code that will pick a file at random.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Be aware that unless the code uses some dynamic variable such as a value from a record, the same image will display for every record on Continuous View form or on a report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Take a picture from a form with usb camera **need help
    By lwilson2k1 in forum Programming
    Replies: 4
    Last Post: 11-15-2013, 12:37 PM
  2. Picture rotating on display Problem
    By justphilip2003 in forum Forms
    Replies: 2
    Last Post: 04-25-2013, 05:44 PM
  3. Replies: 3
    Last Post: 05-31-2012, 02:49 PM
  4. Replies: 1
    Last Post: 05-30-2012, 03:51 PM
  5. Displaying a picture on a form
    By kydbmaster in forum Forms
    Replies: 4
    Last Post: 04-04-2009, 07:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums