Results 1 to 13 of 13
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Changing image picture property

    I have a continuous form where each record contains a "box color name" field. The form has an un-bound image control wherein I want to dynamically set the picture property as the form populates. I tried to bind the image control with a function reference where the function would obtain the "box color" and set the image control accordingly. However, Access issues an error indicating it can't Open the link reference. I really need the function, or some mechanism, to test the value of "BoxColor", as it can be null.

    Click image for larger version. 

Name:	000.jpg 
Views:	21 
Size:	46.3 KB 
ID:	48048


    Code:
    Option Compare Database
    Option Explicit
    Public Function SetBox(BoxName As Variant)
    If Not IsNull(BoxName) Then Me.imBox.Picture = "c:\Meds\" & BoxName & ".jpg"
    End Function
    The appropriate image changes with each record, so maybe I need to learn a new method?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Wouldn't that be Me.Boxname?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    BoxColor is the field name in the RecordSource query. BoxName is simply the name given to the parameter to the function. E.g., if BoxColor is Blue, then that's the string that would be passed to the function. BoxName has to be variant, as it's entirely possible it could be null.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Yes, but you are referring to a control called imBox?
    Plus as a continuous form, won't all unbound images show the same?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Plus as a continuous form, won't all unbound images show the same?
    That's what I'm trying to overcome. It's kind of like an OnFormat event on a form so I can stipulate which jpg file to use. I might not be able to do what I want?

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Your function is not returning a value, so:


    Code:
    Public Function SetBox(BoxName As Variant) as String
        If Not IsNull(BoxName) Then 
            SetBox = "c:\Meds\" & BoxName & ".jpg"
        Else
            Setbox = ""
        Endif        
    End Function
    Last edited by davegri; 06-16-2022 at 10:03 PM. Reason: added red emphasis

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Sorry for the incompletion in the post. Since the editor wouldn't accept my insertion of "=SetBox([BoxColor])", I didn't bother with any other considerations regarding the function. However, the scope of the module should have been such the Me.imBox.Picture = "c:\Meds" & BoxName & ".jpg" would be the equivalent of a string returned by the function as you see in the OP.

    Bill

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you have the picture type as linked - so picture is looking for string. In the imagebox, just put [boxcolor] in the controlsource if it is a full path and remove from the picture property. You can also try putting =setbox([boxcolor]) in the controlsource instead

  9. #9
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    If it's unbound you won't be able to display a different picture on each line.
    You could however link the control to an underlying calculated query field, and put a default as a blank image file, if there isn't a file??
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    You can also try putting =setbox([boxcolor]) in the controlsource instead
    Yes, I thought that would work if I bound the control to a function, but if you take a look at the OP you'll see where the design editor wouldn't allow the function reference, which led to the OP to begin with.

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    You could however link the control to an underlying calculated query field
    I did think of that, but in my infinite wisdom concluded that if binding the control to a function didn't work that wouldn't work either............ so much for infinite wisdom! Setting the Data property to "Picture" and adding Picture: "c:\Meds" & [BoxColor] & ".jpg" to the form's RecordSource query, and adding "Blank.jpg" to the image library did the job.
    Thanks,
    Bill

  12. #12
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Glad you have it solved.
    Sometimes the simpler solution is the easiest one...
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  13. #13
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Sometimes the simpler solution is the easiest one...
    Right you are, AMEN!

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

Similar Threads

  1. Image Control - Picture Orientation
    By ironfelix717 in forum Programming
    Replies: 1
    Last Post: 08-03-2020, 07:21 PM
  2. Changing Image with each click of Image.
    By mainerain in forum Access
    Replies: 7
    Last Post: 01-19-2020, 07:05 PM
  3. Change picture property of image control
    By GraeagleBill in forum Forms
    Replies: 6
    Last Post: 09-12-2019, 03:23 PM
  4. Replies: 7
    Last Post: 11-08-2013, 08:28 PM
  5. picture image link on a table textbox
    By john_gringo in forum Access
    Replies: 5
    Last Post: 11-04-2011, 02:21 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