Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Multi-select listbox help!

I'm trying to build an SQL string that uses a multi-select listbox as
its parameters...but, I'm not sure how to do it. I know how to create
a variable and assign it to the value of a combo box, for example.

How do I use a multi-select's listbox multiple values as multiple
parameters for an SQL string?

TIA...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Multi-select listbox help!

This is untested and assumes something is selected in the list but should
give you the general idea. I've assumed a string equivalent field type,
hence the single quotes around the items.

Dim lCounter as Long
Dim strSQL as string

strSQL = "SELECT * FROM MyTable Where FieldName IN ("

With lstBox
For lCounter= 0 to .ListCount - 1
if .Selected then
If Right(strSQL,1) = "'" Then strSQL = strSQL & ","
strSQL = strSQL & "'" & .List(.Listindex) & "'"
End If
Next LCounter
End With
strSQL = strSQL & ")"

Robin Hammond
www.enhanceddatasystems.com

"John" wrote in message
om...
I'm trying to build an SQL string that uses a multi-select listbox as
its parameters...but, I'm not sure how to do it. I know how to create
a variable and assign it to the value of a combo box, for example.

How do I use a multi-select's listbox multiple values as multiple
parameters for an SQL string?

TIA...



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Multi-select listbox help!

Robin, does your code use a multi-select list box? I keep getting "not
optional" errors on the "IF .selected then" statement.

I'm not too familar with Excel forms (I've done mostly Access
programming), and I'm having problems with the multi-select list box
as a parameter "builder".

"Robin Hammond" wrote in message ...
This is untested and assumes something is selected in the list but should
give you the general idea. I've assumed a string equivalent field type,
hence the single quotes around the items.

Dim lCounter as Long
Dim strSQL as string

strSQL = "SELECT * FROM MyTable Where FieldName IN ("

With lstBox
For lCounter= 0 to .ListCount - 1
if .Selected then
If Right(strSQL,1) = "'" Then strSQL = strSQL & ","
strSQL = strSQL & "'" & .List(.Listindex) & "'"
End If
Next LCounter
End With
strSQL = strSQL & ")"

Robin Hammond
www.enhanceddatasystems.com

"John" wrote in message
om...
I'm trying to build an SQL string that uses a multi-select listbox as
its parameters...but, I'm not sure how to do it. I know how to create
a variable and assign it to the value of a combo box, for example.

How do I use a multi-select's listbox multiple values as multiple
parameters for an SQL string?

TIA...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Multi-select listbox help!

Sorry, as I said, it was done on the fly. It should be

If .Selected(lCounter)

Robin Hammond
www.enhanceddatasystems.com

"John" wrote in message
om...
Robin, does your code use a multi-select list box? I keep getting "not
optional" errors on the "IF .selected then" statement.

I'm not too familar with Excel forms (I've done mostly Access
programming), and I'm having problems with the multi-select list box
as a parameter "builder".

"Robin Hammond" wrote in message

...
This is untested and assumes something is selected in the list but

should
give you the general idea. I've assumed a string equivalent field type,
hence the single quotes around the items.

Dim lCounter as Long
Dim strSQL as string

strSQL = "SELECT * FROM MyTable Where FieldName IN ("

With lstBox
For lCounter= 0 to .ListCount - 1
if .Selected then
If Right(strSQL,1) = "'" Then strSQL = strSQL & ","
strSQL = strSQL & "'" & .List(.Listindex) & "'"
End If
Next LCounter
End With
strSQL = strSQL & ")"

Robin Hammond
www.enhanceddatasystems.com

"John" wrote in message
om...
I'm trying to build an SQL string that uses a multi-select listbox as
its parameters...but, I'm not sure how to do it. I know how to create
a variable and assign it to the value of a combo box, for example.

How do I use a multi-select's listbox multiple values as multiple
parameters for an SQL string?

TIA...



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox multi selection Jorge Rodrigues Excel Programming 3 September 7th 04 11:06 PM
multi select listbox Paul Mueller Excel Programming 2 June 10th 04 09:08 PM
populating a multi-column Listbox Tom Ogilvy Excel Programming 3 April 26th 04 08:26 PM
Multi-columns in a ListBox Tom Atkisson Excel Programming 1 October 5th 03 10:27 PM
Extract values from a multi-select multi-column list-box Peter[_20_] Excel Programming 5 September 28th 03 04:04 PM


All times are GMT +1. The time now is 08:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"