Page 3 of 5 FirstFirst 12345 LastLast
Results 31 to 45 of 71
  1. #31
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37

    Quote Originally Posted by ItsMe View Post
    Make sure your ListBox Control has the correct properties. You will need the Multi Select property adjusted. Go ahead and use "Extended" for the Multi Select property in the "Other" tab in the property sheet.
    Yea I did that too

  2. #32
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is a sample DB using the code I provided. Take a look at the properties for the list box. The only thing I can think of that would cause the error you describe would be the Multi Select property.
    Attached Files Attached Files

  3. #33
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    Quote Originally Posted by ItsMe View Post
    Here is a sample DB using the code I provided. Take a look at the properties for the list box. The only thing I can think of that would cause the error you describe would be the Multi Select property.
    The form I created was off a query... Idk how much of a difference that makes.
    So its like a form that has the record source of query.... so you open the form and run it runs that query... Basically the listbox is kind of a parameter... As if only open the records that have the selected values. It works great with single selection.. but not multi

    I opened your database. When I make selections and clikc the command button, Nothing happens

  4. #34
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by KBAR12 View Post
    ...When I make selections and clikc the command button, Nothing happens.
    The results are displayed in the immediate window. The keyboard shortcut to the immediate window is Ctrl+G.

    Since you state, "It works great with single selection.. but not multi", and you do not see anything happening in the DB that I uploaded, I will guess there is more code in your click event than what you posted.

  5. #35
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    Quote Originally Posted by ItsMe View Post
    The results are displayed in the immediate window. The keyboard shortcut to the immediate window is Ctrl+G.

    Since you state, "It works great with single selection.. but not multi", and you do not see anything happening in the DB that I uploaded, I will guess there is more code in your click event than what you posted.
    Sorry that's not what I meant. It works great single selection without the VBA CODING.

  6. #36
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    I was hoping to get the resutls in a query.
    So basically using the form as a filter.

  7. #37
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The code I posted is tested. There is a working example of the code here. If you are still having trouble, you can upload your DB here for analysis. Remove personal data, compact and repair, and zip the file.

    I understand you need more than having the results print to the immediate window. You need to accomplish the first step before you can cross the finish line.

  8. #38
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    MultiSelectTest.zip


    I created a new sample DB.

  9. #39
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    Quote Originally Posted by KBAR12 View Post
    MultiSelectTest.zip


    I created a new sample DB.
    Its a much simpler database than I was working with but the idea is the same.
    I want to be able to select multiple states and click the button to run a filtered query
    THANKS SO MUCH FOR YOUR HELP! I REALLY DO APPRICIATE IT!

  10. #40
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    I tried the code on this new sample database and got the same error.
    The following code was highlighted:
    lngID = Me.List0.Column(0, varSelection)
    *NOTE* List box is named List0
    I don't know what lngID is... am I suppose to replace it with somehting else?

  11. #41
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I did a couple of things. The control button on your form had an embedded macro. I removed the macro by remove the text in the Control Source property of the Control Button.

    I created a click event handler in VBA and pasted the code from post #8 in the click event.

    I changed the line of code
    Dim lngID As Long 'Assumes the value in the first column is a number
    and
    lngID = Me.List0.Column(0, varSelection)
    'Insert code here to do something
    Debug.Print lngID

    to
    Dim strState As String 'Assumes the value in the first column is text
    and
    strState = Me.List0.Column(0, varSelection)
    'Insert code here to do something
    Debug.Print strState

    respectively. I then changed the property, "Multi Value", for the list box to "Extended".

    Now you can view the results in the immediate window by using the keyboard shortcut Ctrl+G.

    I noticed that you have two tables in the DB you uploaded. One uses an autonumber as a PK and the other uses text as a PK. So, table1 stores the literal text from your States table. It is OK to do this but you may want to consider using an autonumber field for your States table and using the Autonumber field as you PK. If you do not use the Autonumber field, consider limiting the characters allowed in your text field to two characters or maybe four.

    I took the liberty of adding a table to the DB I uploaded here. This table is a table I often use in my DB's. It has three columns: PK, postal abbreviation, and full name. It makes it easier for a User to see the full state name when they are making the selection. After the selection is made, you can display the abbreviation and store the PK in the relative tables.
    Attached Files Attached Files

  12. #42
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    Actually one of the table didn't have a Primary Key, The only reason I had it created was to allow only selected value as input for a form I did not creat in this sample DB.

    I tested the DB you posted and it works. I don't quite understand the results though. If I select NJ & PA in the immediate window I see NJ & Pa. (It opens the VBA coding window and at bottom there is the Immediate winow and I just see NJ & PA)
    I want to be able to see the enitre data. For example in the Sample DB I would like for all the customers to show up if they are from NJ & PA if that's my selection in the form.

  13. #43
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Well, you need to be able to walk before you can run. A developer will typically retrieve the PK values from a listbox or combobox and then apply the results to a query or VBA procedure or both. This is where the "'Insert code here to do something" will come into play. Now that we have managed the first hurdles, the next steps can be considered.

    Post #15 would be one approach.

    You need to first decide what the PK is for your states table. Then you need to decide what you want to do with the user input (the data retrieved from the list box).

    What is your goal? Are you trying to open another form, open a report, create an email? You can add the results from the listbox to a WHERE clause in a query for instance or add the results to a Where Criteria of a form's filter property.

  14. #44
    KBAR12 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    37
    Quote Originally Posted by ItsMe View Post
    Well, you need to be able to walk before you can run. A developer will typically retrieve the PK values from a listbox or combobox and then apply the results to a query or VBA procedure or both. This is where the "'Insert code here to do something" will come into play. Now that we have managed the first hurdles, the next steps can be considered.

    Post #15 would be one approach.

    You need to first decide what the PK is for your states table. Then you need to decide what you want to do with the user input (the data retrieved from the list box).

    What is your goal? Are you trying to open another form, open a report, create an email? You can add the results from the listbox to a WHERE clause in a query for instance or add the results to a Where Criteria of a form's filter property.
    My PK value is fine. Think of it as a job # ... autonumber is fine.
    I would like to be able to open a new query I guess (or filtered an existing one). So as you saw in the database there was a query. I would like to be able to pick the values from the form (example the states), and all the customers that belong to those selected states show up (basically there data from the main data table show up).

  15. #45
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I have a solution for you. I will post it soon.

Page 3 of 5 FirstFirst 12345 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multi-Select Listbox
    By RayMilhon in forum Forms
    Replies: 5
    Last Post: 03-04-2014, 11:54 AM
  2. Search using a multi select listbox
    By noobaccess in forum Access
    Replies: 13
    Last Post: 12-04-2012, 07:06 AM
  3. Replies: 6
    Last Post: 11-02-2012, 12:48 PM
  4. multi select listbox
    By crowegreg in forum Forms
    Replies: 3
    Last Post: 07-28-2012, 01:48 PM
  5. Replies: 11
    Last Post: 09-22-2011, 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