Results 1 to 5 of 5
  1. #1
    J4zzee is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    2

    Lightbulb VBA Code for Range Selection

    Hello everyone!



    My project is a little bit complex to describe it in a post. I will simplify it to make it easy to read.

    I have a starting point. Example: S=4
    I have an ending point. Example: E=10
    I would like to write a VBA code that will select (in my project on a multivalue combobox) the following numbers: 4,5,6,7,8,9,10.

    I hope my problem is clear enough. If not, I can then explain the project.

    Thank you for your support!
    Regards.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Not really enough info.

    A multi-value combobox must be bound to a multi-value field. Recommend against use of multi-value field.

    Also, I don't think VBA can directly select items of multi-select combobox list. VBA can save values to multi-value field. The code is rather complex.

    But again, advise not to use multi-value field.
    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
    J4zzee is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    2
    Quote Originally Posted by June7 View Post
    Not really enough info.

    A multi-value combobox must be bound to a multi-value field. Recommend against use of multi-value field.

    Also, I don't think VBA can directly select items of multi-select combobox list. VBA can save values to multi-value field. The code is rather complex.

    But again, advise not to use multi-value field.

    Thank you for your reply. I am currently using this code:

    "Me.[Combobox].SetFocus
    Me.[Combobox].ListIndex = 0

    Me.[Combobox].Selected(0)=True" ===> this will select the first item in the list.

    Actually this code works. I just want the part of the code that will identify what needs to be selected.

    I will try to provide more input:
    I have two variables S and E that may go from 0 to 10, E always being greater than S.
    Depending on the values taken by these two variables, I want to select several items from my Combobox.

    if S = 1 and E = 5, I want then to select items 1,2,3,4,5 (set them to true in my code above).

    Thank you!

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    your vagueness in describing what you want means we have to guess but based on this
    Me.[Combobox].SetFocus
    Me.[Combobox].ListIndex = 0

    Me.[Combobox].Selected(0)=True" ===> this will select the first item in the list.


    Actually this code works. I just want the part of the code that will identify what needs to be selected.
    - my guess would be something like
    Code:
    Dim S as long
    Dim E as long
    Dim i as long
    
    S=1
    E=10
    for i=S To E
        Me.[Combobox].Selected(i)=True
    next i
    no idea where you would put this code, what happens to items outside the specified range, if E is greater that the maximum number of possible options, etc

    As already said, multivalue combos have limited functionality and are really only intended for simple applications

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I tested code. It works.

    I had confused this with selecting items in quick filter drop down of datasheet form.

    Still advise not to use multi-value field.
    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. Query by Date Range Selection in Combo
    By nick404 in forum Queries
    Replies: 2
    Last Post: 08-16-2016, 02:20 PM
  2. Replies: 3
    Last Post: 01-26-2016, 01:56 PM
  3. Printer Selection in VBA code
    By trevor40 in forum Reports
    Replies: 2
    Last Post: 03-08-2014, 03:31 PM
  4. Replies: 7
    Last Post: 04-30-2012, 10:52 AM
  5. Code to combine report filter and date range
    By rhubarb in forum Reports
    Replies: 17
    Last Post: 10-28-2011, 03:08 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