UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> On Button Press Display List Box, Access 2016    
 
   
chalupabatman
post Feb 27 2020, 10:56 AM
Post#1



Posts: 88
Joined: 12-April 17



Hello on a button press event on a user form I want to display a list box that gives the user the option to select 7 Days, 30 Days, All - and based off the selection pass that to the where clause of a query that is being built by the vba.

How can I have a message box display that has the pre-set inputs and capture the inputs thought vba?
Go to the top of the page
 
theDBguy
post Feb 27 2020, 11:15 AM
Post#2


UA Moderator
Posts: 77,736
Joined: 19-June 07
From: SunnySandyEggo


Hi. You could use a popup form to offer the choices to the user.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
chalupabatman
post Feb 27 2020, 12:47 PM
Post#3



Posts: 88
Joined: 12-April 17



If I follow you, when the user presses the button, have a second form open with a list box that has the options, right?

If that is the case, how would I "capture" what selection was made from the list box and pass it to the VBA to use in the WHERE clause of my SQL?
Go to the top of the page
 
chalupabatman
post Feb 27 2020, 01:23 PM
Post#4



Posts: 88
Joined: 12-April 17



okay, i was overcomplicating it.

From parentform - in the button click event i'd add code to display the sub-form
From subform - in the button click event THERE i'd add the code to capture the value from the listbox and build the query and export the query results to excel

My last question tho is how do I use vba to capture the value of a listbox on my form?
Go to the top of the page
 
theDBguy
post Feb 27 2020, 01:31 PM
Post#5


UA Moderator
Posts: 77,736
Joined: 19-June 07
From: SunnySandyEggo


Hi. For a multi select listbox, it gets a little tricky. If it's a single select listbox, the value of the listbox is the same as the one item selected. But for a multi select listbox, the value of the listbox is always null. So, to get al the selections, you'll have to loop through the ItemsSelected collection. I can't post any sample code right now because I'm on my phone, but you could search for it and see a lot of examples. Good luck.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
chalupabatman
post Feb 27 2020, 01:35 PM
Post#6



Posts: 88
Joined: 12-April 17



Thanks for the tip. It is set to be a single select list box (Or at least I think I set it as that) -

This is the code I have which seems to be working. Do you see any flaws with this code?

CODE
    Dim selValue As String
    
    selValue = Me.lstbxRange.Column(0)
Go to the top of the page
 
Larry Larsen
post Feb 27 2020, 01:47 PM
Post#7


UA Editor + Utterly Certified
Posts: 24,535
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi
PMFJI...

This UA example/Demo should scale up and work, by JD..


Link:Creating a Query that uses a Multi-select Listbox as Criteria.

HTH's


--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
chalupabatman
post Feb 27 2020, 02:35 PM
Post#8



Posts: 88
Joined: 12-April 17



perfect. Thanks for the help all.
Go to the top of the page
 
theDBguy
post Feb 27 2020, 02:41 PM
Post#9


UA Moderator
Posts: 77,736
Joined: 19-June 07
From: SunnySandyEggo


Hi. You're welcome. Larry and I were happy to assist. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    8th April 2020 - 04:47 PM