Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107

    button picture from attachment

    I have a table items with two attributes: description (text) and picture (attachment field)
    I want to make a form that contains a buttons for each item, items with picture are shown in the button's picture, otherwise their description is shown in the button's caption as follows:
    Click image for larger version. 

Name:	Capture.JPG 
Views:	30 
Size:	39.5 KB 
ID:	41102
    I used the following code to do it
    Code:
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT description,picture.FileName FROM Item")
    rs.MoveFirst
    Do Until counter = 7
          Me.Controls("Item" & counter).Caption = rs![description]
          Me.Controls("Item" & counter).Picture = IIf(IsNull(rs![picture.FileName]), "", rs![picture.FileName])
          counter = counter + 1
          rs.MoveNext
    Loop
    rs.Close
    The form works fine directly after I add/modify the attachment fields in the table, but if I open the form without making any updates to the attachment fields, it shows the following error: can not open the file "Hamburger.bmp"



    Note that all the pictures in the attachment fields are embedded inside the table and I don't want to use any external folder to store pictures

    Any idea why pictures are shown after updating them only? What should I do to make embedded picture attachments accessible after reopening the db without updating them?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Attachment field is a type of multi-value field. I don't use multi-value fields.

    Is there only one image in Attachment field?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107
    Yes each item has only one picture. Also some items do not have a picture
    Do you think the attachment is not the best choice for my case?

    Quote Originally Posted by June7 View Post
    Attachment field is a type of multi-value field. I don't use multi-value fields.

    Is there only one image in Attachment field?

    If you want to provide db for analysis, follow instructions at bottom of my post.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Why don't you just embed the picture in the button and do away with the attachment field?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107
    Quote Originally Posted by Micron View Post
    Why don't you just embed the picture in the button and do away with the attachment field?
    The items are not entered by me, the user enters the items and specifies whether each item has a picture or not

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Since you get an error, I presume can't dynamically set button Picture property with image from attachment field. Image would have to be loaded from external location. I expect that is what is happening when image is first attached.

    Only alternative I see is code setting visibility of image controls and textboxes.
    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.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    the user enters the items and specifies whether each item has a picture or not
    Well I'm confused by that. Your post is about getting pictures to show up on buttons so that someone can select an item that either looks like the picture or matches the text if there is no picture. I don't see how that's related to the user specifying whether or not the button has a picture on it. AFAIK, a command button image has to be linked or embedded, and since you don't want to link, that leaves you only one option.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107
    Yes I agree with you, I think there is no way to load embedded pictures into buttons

  9. #9
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107
    Quote Originally Posted by Micron View Post
    Well I'm confused by that. Your post is about getting pictures to show up on buttons so that someone can select an item that either looks like the picture or matches the text if there is no picture. I don't see how that's related to the user specifying whether or not the button has a picture on it. AFAIK, a command button image has to be linked or embedded, and since you don't want to link, that leaves you only one option.
    I am working on a restaurant software that allows users to specify their items (description/picture), and they have the choice to show a caption or a picture on the button. I am trying my best to avoid links so that users do not have access to the the image folders and do not accidentally rename the folder or delete it.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Where do these images come from? Users find them wherever they want? When user finds image code should be able to copy to a folder location users are not even aware of. Save image name in field, not folder path. Hard code path. Since image path is only in code, users should not know it. Do what you can to prevent users viewing code.

    I said "should be able" because I ran into issues of programmatically copying files. Used to be able to do it until office computers were upgraded.

    Is this a split db?
    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.

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Quote Originally Posted by bilalo View Post
    I am working on a restaurant software that allows users to specify their items (description/picture), and they have the choice to show a caption or a picture on the button. I am trying my best to avoid links so that users do not have access to the the image folders and do not accidentally rename the folder or delete it.
    If the images are small f8les, you could add them to the Image Library for the app without significantly bloating the app size.
    The images are then part of the app.

    I would also lock down the app as far as possible so users can globally choose pre-defined images and/or text for all those POS command buttons but not alter individual buttons.

    For info, there are 3 possible settings for command button images: linked, embedded and ​shared.
    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

  12. #12
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107
    Quote Originally Posted by isladogs View Post
    If the images are small f8les, you could add them to the Image Library for the app without significantly bloating the app size.
    The images are then part of the app.

    I would also lock down the app as far as possible so users can globally choose pre-defined images and/or text for all those POS command buttons but not alter individual buttons.

    For info, there are 3 possible settings for command button images: linked, embedded and ​shared.
    What is a shared image?
    My problem with embedded images is that they can be added to buttons only directly after attaching them. But if I close the db and then reopen it, they are not visible anymore to buttons.
    Does shared images solve this problem?

  13. #13
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107
    Quote Originally Posted by June7 View Post
    Where do these images come from? Users find them wherever they want? When user finds image code should be able to copy to a folder location users are not even aware of. Save image name in field, not folder path. Hard code path. Since image path is only in code, users should not know it. Do what you can to prevent users viewing code.

    I said "should be able" because I ran into issues of programmatically copying files. Used to be able to do it until office computers were upgraded.

    Is this a split db?
    Yes, it is a split db, and that is exactly what I am doing currently, I ask my users to put all their pictures in a specific folder and then they open a form that allows them to attach each picture to its corresponding item as links and I save the pictures paths inside the db. And then their is another form that loads those images and puts them inside buttons.
    But I still think this is not the optimal solution, users are allowed to add maximum 18 pictures (60 KB each) to the db, therefore I am not afraid of bloating the app size. But, if I can allow the users to save their pictures inside the db without using an external folder, that would be much preferable and less error prone.

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Well, if must embed image in table, then code would have to extract to folder location in order to use for embedding in button. Image file could be deleted after embedded into button.

    https://docs.microsoft.com/en-us/off...chments-in-dao

    https://sourcedaddy.com/ms-access/wo...nt-fields.html

    However, this entire process is not making sense. Won't these user-embedded images on buttons be lost every time a new version of frontend is distributed?
    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.

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I think this is a POS app that's for sale.
    One could also consider other options. Maybe an image control (has picture property) but probably requires image pairs (normal and highlighted). Or maybe tranparent borderless buttons over images, or stop trying to control everything a user might do. Does M$oft worry that you might delete your folder full of Word documents?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 01-15-2017, 09:53 AM
  2. Picture / Vedeo File Attachment
    By rkalapura in forum Forms
    Replies: 3
    Last Post: 06-14-2012, 01:18 PM
  3. Replies: 2
    Last Post: 09-02-2011, 09:16 AM
  4. Attachment Picture
    By cggriggs in forum Forms
    Replies: 0
    Last Post: 06-14-2011, 10:17 AM
  5. Change a Picture in an Attachment
    By ksmith in forum Access
    Replies: 2
    Last Post: 08-18-2010, 11:17 AM

Tags for this Thread

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