Results 1 to 11 of 11
  1. #1
    CH1LL is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    5

    Adding checkboxes to listbox control without multiselect


    To start, I am happy to share the file I am working on as it is a fun project and not for work or anything sensitive.

    I am creating a database of trading cards. I currently have a few tables with data and a form that lets me filter cards. Easy enough, right? Here is where it has gotten complicated and should provide some explanation as to why I am asking this question.

    I want to be able to view also an image of the card as part of the query results. There are a ton of cards, so rather than store all of these files locally, I have a field in a table that contains a URL link to a web page. The form has three combo boxes that act as the filters. The afterupdate event on these comboboxes then sends a requery to a listbox. The listbox's rowsource is set to a SQL SELECT statement based on whatever is in the combobox filters. In the end, all of the results then make their way into a listbox.

    NOW!.... I am doing it this way because there is a hidden column in the listbox that the listbox control is bound to. This column is the one that contains the URL for the picture. The end result is that you can choose the filters, the results make their way into the listbox, and then when you click on one of the records in the listbox, it feeds to a webBrowser control that displays the image of the card.

    This is all great and it works how I want it to (again open to better suggestions to achieve the same end result). The next feature I want to add is the ability to create and save watchlists, i.e. separate lists of cards that I want as their own lists/tables. Examples would be "Owned Cards" or "Cards to Buy". What I want to be able to do is add check boxes in the listbox control I mentioned above so that I can select a few of them at once and then add a button later to loop through the listbox and insert the results that are checked into a watchlist table. My problem is that if I enable multiselect in the listbox, the webBrowser control stops working because I am no longer referencing a single URL for the control to look up.

    This is a very long winded post, I apologize. Again, I am happy to send the file I am working on, especially if there are any fans of Pokemon cards. Thank you!

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    why use a web browser control when there is an Image control specifically to display images?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    CH1LL is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    5
    I used the web browser control because I couldn't figure out how to get the Image control to properly reference the URL from the listbox. When using the listbox, I can bind the whole listbox to the column containing the URL. Then I can set the control source of the web broswer control to just the listbox as a whole.

    Click image for larger version. 

Name:	lbox_CardImg.png 
Views:	29 
Size:	4.6 KB 
ID:	50673

    I am by no means an access expert haha, if you know of a way to accomplish the same thing with the image control that would actually be preferred because then I can set the image to resize automatically.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You have so many pics of cards that you can't store them locally? If you must use a browser control then my guess is you should remove the url property and only assign it via button click. What I don't get how the browser control can show anything if you feed it multiple url's from the listbox. If you could add checkboxes to a listbox control (don't think so but I don't recall ever trying) and don't use the multi select feature, how do you intend to pass multiple choices to the browser control? If you intend to loop the choices then just multi select, and as I mentioned, don't bind the browser control to the listbox. Loop instead and pass the url to the browser control. Still, I don't get what you intend to do with multiple selections of any sort and one browser control.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CH1LL is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    5
    Currently there over 16,600 imaged that would need to be stored locally. I tried doing this in the excel file that I used to import the data and the file ended up being over 10GB and was too slow. Figured it would be the same fate for Access.

    Its currently set up so that when I select a record in the listbox, it passes that URL to the web browser and the image shows. This is how I want it to work. I noticed exactly what you mentioned when I enabled multi select, which is that the web browser wont load an image because it cant handle multiple URLs.

    The though for the check boxes was not to pass multiple URL records to the web browser control, but as a way to eventually use a button and vba loop to essentially look through all records in the listbox that are checked, and then insert them into a table that the user can choose. Thats where my head has been hurting, I am not sure how to add checkboxes that simply act as boolean flags without passing that record to the web browser control. Does that provide more context? Essentially the goal is to add checkboxes to the listbox without it "selecting" that record. I just want the checkbox to store a true or false for that record without selecting it and therefore trying to pass it to the web browser control

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Suspect your approach is wrong.

    But first - is the only reason you are storing your images on the web is so you can use a web control and/or the space required? Or perhaps it is a collectors site? Downloading anything from the web takes much longer that storing the images locally (not in Access but in a specified folder)

    Suspect your approach should be to use a continuous form and (perhaps) have a combo or listbox to enable you to set criteria (not filter) as required. A list of 16,000+ records is really not manageable. There are ways to use a continuous form as a 'multi select' form - see this example https://www.access-programmers.co.uk...-boxes.323395/

    I want to add is the ability to create and save watchlists, i.e. separate lists of cards that I want as their own lists/tables
    you don't have separate tables, you have one table and include in the record a flag or FK to a table for your watchlists. If an image can be in more than one watchlist then you also need a linking table between the images table and the watchlist table

    Edit: You might like to download the example here https://www.access-programmers.co.uk...asheet.320624/ to see what I mean about images in a continuous form

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Currently there over 16,600 imaged that would need to be stored locally. I tried doing this in the excel file that I used to import the data and the file ended up being over 10GB and was too slow. Figured it would be the same fate for Access.
    You would not store the pictures in access. The pictures would be stored in a folder outside of access and you would only store the path to the file as text in the database.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #8
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Since you already have urls in your table. Give your web browser control some good use, it does not have the limits you think it has, it's quite contrary to that.
    Click image for larger version. 

Name:	cards2.jpg 
Views:	25 
Size:	44.5 KB 
ID:	50677

    Check the attached database.

    Here's the code for the listbox to feed the browser:
    Code:
    Private Sub lstResults_AfterUpdate()
        If Me.lstResults.ListCount > 0 Then
        'start over
            doc.body.innerHTML = ""
            Dim lst As ListBox
            Set lst = Me.lstResults
            Dim s As Variant
            
            'make canvas
            Set container = doc.createElement("div")
            With container.Style
                .minHeight = "100%" 'cover entire screen
                .backgroundColor = "f5f5f5" 'container background
                .display = "flex" 'same row
                .flexWrap = "wrap" 'responsive
                .justifyContent = "center" 'center cards horizonally
                .padding = "20px" 'inner spacing
            End With
            
            doc.body.appendChild container
            
            'use listbox
            For Each s In Me.lstResults.ItemsSelected
                Debug.Print Me.lstResults.ItemData(s), Me.lstResults.Column(2, s)
                
                'card
                Set card = doc.createElement("div")
                With card.Style
                    .backgroundColor = "fff" 'white card
                    .margin = "5px" 'outer spacing
                    .padding = "10px 30px" 'inner spacing
                    .Width = "100px" 'fixed width
                    .Height = "100px" 'fixed height
                    .overflow = "hidden" 'long text cuts off
                    .borderRadius = "10px" 'round border
                    .boxShadow = "0 2px 10px rgba(0, 0, 0, 0.1)" 'shadow
                End With
                
                'img
                Set img = doc.createElement("img")
                img.src = Me.lstResults.Column(2, s)
                With img.Style
                    .borderRadius = "50%" 'round border
                    .display = "block" 'center image
                    .margin = "0 auto" 'center image
                End With
                
                'append selection
                card.appendChild img
                container.appendChild card
            Next s
        End If
    End Sub
    It could be much simpler if we remove the styling, but it looks cool with styles.
    Attached Files Attached Files

  9. #9
    CH1LL is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    5
    @CJ London and @moke123
    I dont mind storing the files locally on my computer, but if I want to send the files to my friends for them to use, they would also need a large folder of pictures to go with it as well, right? Along with the code changed to fit where they store the folder? If the file is going to be shared, would it make more sense to just use the urls? I suspect I am not doing it the most efficient way as well

    And for the flags in the one table, I would need to make my "Create Watchlist" button insert a new column to the table rather than just create a new table, correct?

  10. #10
    CH1LL is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    5
    @Edgar
    This is very clever. So youre using VBA so set a container and whenever a record is selected from the list it creates a new card where the contents is the image?
    img.src is set to column 2, that column can be URLs?

  11. #11
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Quote Originally Posted by CH1LL View Post
    @Edgar
    This is very clever. So youre using VBA so set a container and whenever a record is selected from the list it creates a new card where the contents is the image?
    img.src is set to column 2, that column can be URLs?
    Yes, the web browser control starts as an empty canvas when the form loads. Then, whenever an item is selected in the listbox, the canvas is emptied again to receive the new set of images selected. There's a main container filling the entire web browser screen. There's also a "card" item and an img tag that shows the picture. In the example, the urls are stored in a table, this table feeds the listbox. No need to download any image, just store urls and the web browser will show them neatly.

    Lots more can be done, you can even bypass your combobox filters and the listbox too. Keep in mind that the web browser control is enabled for web development. That's a lot of power.

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

Similar Threads

  1. How to set Selected in multiselect listbox?
    By DavidFord in forum Access
    Replies: 11
    Last Post: 08-23-2019, 11:37 AM
  2. Adding Records from MultiSelect ListBox
    By Voodeux2014 in forum Forms
    Replies: 3
    Last Post: 10-16-2015, 09:22 AM
  3. Multiselect Listbox
    By wwhit in forum Forms
    Replies: 19
    Last Post: 03-09-2015, 02:58 PM
  4. Replies: 4
    Last Post: 06-24-2013, 07:34 AM
  5. Listbox multiselect status
    By Sam23 in forum Programming
    Replies: 5
    Last Post: 03-06-2012, 01:13 PM

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