473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

List box output string

I have a list box on a form that will contain a list of course modules for
the school where I work. I want to allow the user to select single or
multiple modules ie Modue M10S and M10SA. what I want to do is create a
dynamic sql statement that will have something like:

Where tblx.module = "M10S" And "M10SA"

question one: how do I extract the string from the list box if more than one
item is selected, (I assume it may have some kind of count for the number of
items selected?)

question 2 : I assume I then need to use this count in the VBA to build up
the qry String?

regards in advance.

Peter
Nov 13 '05 #1
3 2108
Hi Peter

(Warning Untested air code)
** Code Start**
Dim varItems as Variant
Dim strSelect as String
Dim strWhere as String
Dim strSQL as String
Dim strMods as String

strSelect = "SELECT * FROM YourTable "

For Each varItems In YourForm!YourListBox.ItemsSelected
If strMods = vbNullString Then
strMods = Chr(39) & YourForm!YourListBox.ItemData(varItems) &
Chr(39)
Else
strMods = strMods & ", " & Chr(39) &
YourForm!YourListBox.ItemData(varItems) & Chr(39)
End If
Next

strWhere = "WHERE module In (strMods);"
strSQL = strSelect & strWhere
** End Code **

Chr(39) is the apostrophe so it could be shortened to "'" That is a double
quote then apostrophe then double quote

Yes this has to done in VBA. You might have to error trap the code to
prevent it running if there are no items are selected in your list box.

Although this will generate the sql for a query, how are you going to
run/view the query? Are you going to create a temporary query? Are you using
this for a recordsource for a form or report?

Jeff
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ch**********@newsg4.svr.pol.co.uk...
I have a list box on a form that will contain a list of course modules for
the school where I work. I want to allow the user to select single or
multiple modules ie Modue M10S and M10SA. what I want to do is create a
dynamic sql statement that will have something like:

Where tblx.module = "M10S" And "M10SA"

question one: how do I extract the string from the list box if more than one item is selected, (I assume it may have some kind of count for the number of items selected?)

question 2 : I assume I then need to use this count in the VBA to build up
the qry String?

regards in advance.

Peter

Nov 13 '05 #2
I am hoping to reference a query with nothing in it and then pass the sql to
it on the fly with it bound to a form, what do you think?
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ch**********@newsg4.svr.pol.co.uk...
I have a list box on a form that will contain a list of course modules for
the school where I work. I want to allow the user to select single or
multiple modules ie Modue M10S and M10SA. what I want to do is create a
dynamic sql statement that will have something like:

Where tblx.module = "M10S" And "M10SA"

question one: how do I extract the string from the list box if more than one item is selected, (I assume it may have some kind of count for the number of items selected?)

question 2 : I assume I then need to use this count in the VBA to build up
the qry String?

regards in advance.

Peter

Nov 13 '05 #3
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message news:<ch**********@newsg1.svr.pol.co.uk>...
I am hoping to reference a query with nothing in it and then pass the sql to
it on the fly with it bound to a form, what do you think?


I see no reason why it shouldn't work. Just use the code at
www.mvps.org/access find the code for using a multiselect listbox for
query parameters... and then pass the where clause to the open event
of the form or whatever...
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steven | last post by:
Hi, I'm creating a custom checkbox list control which will take 2 arraylists as input. (One will contain Names and other will contain 0s and 1s. 0 - uncheck 1- check). I'm able to create the...
0
by: Steven | last post by:
Hi, I'm creating a custom checkbox list control which will take 2 arraylists as input. (One will contain Names and other will contain 0s and 1s. 0 - uncheck 1- check). I'm able to create the...
0
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and...
1
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and...
6
by: Henrik Goldman | last post by:
Hello, I have a dataset which consist of a string username and string hostname as a key and then an integer representing a count as the matching "second" value in a pair. So far I've used...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.