Results 1 to 8 of 8
  1. #1
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146

    Changing Image with each click of Image.

    I would like to be able to have an Image displayed, then be able to click on the Image to change it to a different Image. A total of four Images, just keep stepping through the four Images in a revolving way. Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Are images located in external folder or embedded in table?

    If external folder, use a global variable or TempVars. Code increments value with each click. Value determines which image to load.
    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
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146
    I could put the pictures either way, which ever is easiest/best.

    I'm just a newbie, would I declare a variable like varImage1 in the Global Module then set it to an image somehow?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Embedding files such as images or documents uses up Access 2GB file size limit.

    No, would not set variable with image, set it with sequence number. Variable declared in general module and code behind form to set Image control ControlSource property. Assuming
    each set of 4 images has naming that corresponds to some identifying field in table with a number suffix - something like:
    Code:
    Sub imgPics_Click()
    If gblSeq = 4 Then gblSeq = 0
    gblSeq = gblSeq + 1
    Me.imgPics.ControlSource = "=C:\folderpath\" & Me.fieldname & gblSeq & ".jpg"
    End Sub
    Then would also need to reset global variable when moving to a new record. So code in form Current event:
    gblSeq = 1
    Me.imgPics.ControlSource = "=C:\folderpath\" & Me.fieldname & "1.jpg"

    One issue with global variables is they lose value when code encounters runtime error. Alternatives are to set value of an UNBOUND textbox on form or use TempVars.
    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
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Another approach would be to use two buttons next to the image to move to the next or previous image.
    That approach would also use a 'sequence' approach similar to that suggested by June7
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146
    Thanks June7

    That worked for me except I had to replace Me.imgPics.ControlSource with Me.imgPics.Picture, it didn't seem to like ControlSource

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Glad you figured it out. I've never actually had to do this. Now I see that ControlSource of image control cannot be set programmatically, unlike other controls that have this property. However, can call a function that returns complete image path. But what you have is probably simpler.
    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.

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I just alter the Picture property in the form Current event, so a function isn't really needed if the path is a field in the record. If you have 4 pics related to 1 record, you'd need a parent/child record type of relationship and a way (other than Current event) to cycle through them.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 10
    Last Post: 02-25-2019, 07:36 PM
  2. Replies: 6
    Last Post: 03-22-2018, 12:02 PM
  3. Replies: 1
    Last Post: 12-26-2016, 08:57 AM
  4. Replies: 3
    Last Post: 07-13-2015, 12:07 PM
  5. Replies: 2
    Last Post: 10-10-2011, 10:58 AM

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