|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Executing Functions From a Multiselect Listbox
I have a form with a multiselect listbox setup with the names of queries that I already have setup within Access. I would like to be able to execute those queries from this form, but have the ability to execute at least two or more at a time.
I have scoured the internet for the last two days and have come up with nothing, nor have I been able to find anything similar to what I'm looking to achieve. I have found a number of ways to create queries from a multiselect list box in a form, but no way to execute queries. I am just starting out in VBA, and I know this is going to recquire a substantial amount of code, so I'm reaching out for HELP! Big thanks in advance for helping me out... Paul |
|
#2
|
|||
|
|||
|
Place a command button on your form and in the On Click event paste this code:
Dim strQueryName As String Dim varItem As Variant For Each varItem In Me!ListBoxName.ItemsSelected strQueryName = Me!ListBoxName.ItemData(varItem) DoCmd.OpenQuery strQueryName Next varItem This will open the queries you selected in your list box. Just change the DoCmd.OpenQuery to whatever you wanted to do with the queries that were selected in the list box. Use the correct name of your list box in the above example. lwells |
|
#3
|
|||
|
|||
|
Worked wonderfully...
Thank you, thank you, thank you.... I have a question though: There is a query amongst the list that I plan on running that has a specific criteria in one of the fields, and I would like to know how to run them in succession and when that query comes to run I am asked to enter in the specific criteria. Thank you! Paul |
|
#4
|
|||
|
|||
|
In the query that will have a specific criteria for you to enter manually, in the criteria row below the field to sort on, type in [Enter Specific Criteria] with the brackets.
Then when that query tries to run, it will open the parameter box for you to enter the specific criteria. Was this what you were asking? lwells |
|
#5
|
|||
|
|||
|
That was along the lines of what I was asking...
However, I need it to automatically do it without any input. The criteria is never going to change; it will always be any record that is less than the current month, which is displayed as YearMonth (200507). Is there a way to put that criteria into the VB code that runs the query, and automatically drops in the year and month, or can i use code within the query itself to automate this process, or I am simply stuck with having the user input the particular criteria??? THanks! -Paul |
|
#6
|
|||
|
|||
|
Yes it is possible. What is the datatype for the field, is it a text or a date? If it is a concantinated string calculation from a date field then it will be text.
|
|
#7
|
|||
|
|||
|
The field in the table that it originates from is Text.
|
|
#8
|
|||
|
|||
|
For your criteria, this should work <Format(Date(),"yyyymm")
This will return records older than the current month lwells |
|
#9
|
|||
|
|||
|
I can just drop that into the criteria field in my query?
|
|
#10
|
|||
|
|||
|
Hi lwells,
|
|
#11
|
|||
|
|||
|
Yes that is correct
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Executing Functions From a Multiselect Listbox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|