A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Multiple-select from list



 
 
Thread Tools Display Modes
  #1  
Old July 12th, 2006, 05:17 PM posted to microsoft.public.access.forms
BethHill
external usenet poster
 
Posts: 13
Default Multiple-select from list

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?
  #2  
Old July 12th, 2006, 06:14 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Multiple-select from list

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #3  
Old July 12th, 2006, 08:43 PM posted to microsoft.public.access.forms
BethHill
external usenet poster
 
Posts: 13
Default Multiple-select from list

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #4  
Old July 12th, 2006, 08:54 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Multiple-select from list

You can't use a multi select list box control as a bound control. It will
always return a Null value.
I'm not sure I understand the issue.

"BethHill" wrote:

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #5  
Old July 12th, 2006, 09:15 PM posted to microsoft.public.access.forms
BethHill
external usenet poster
 
Posts: 13
Default Multiple-select from list

Let me give you my scenario:

In the form, there is a multi-select list box with the control source as
"SELECT [tbl Event].[Event ID] FROM [tbl Event]; " This correctly displays
all the records for the Event ID field.

In this list box, there are many records that I have to scroll through in
order to select the ones that I want. I was wondering if there is a way to
display more records in the list box rather than scroll through each of them.



"Klatuu" wrote:

You can't use a multi select list box control as a bound control. It will
always return a Null value.
I'm not sure I understand the issue.

"BethHill" wrote:

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #6  
Old July 12th, 2006, 09:28 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Multiple-select from list

If you are talking about putting multiple [Event ID]s in the list box item (1
id per column), it is possible, but not easy, and would be difficult to
select. How would the user know which column to select? How would you, as
the developer, know which column to use? Is the [Event ID] text that is
meaningful to a user? Is it unique? How many are we talking about?

"BethHill" wrote:

Let me give you my scenario:

In the form, there is a multi-select list box with the control source as
"SELECT [tbl Event].[Event ID] FROM [tbl Event]; " This correctly displays
all the records for the Event ID field.

In this list box, there are many records that I have to scroll through in
order to select the ones that I want. I was wondering if there is a way to
display more records in the list box rather than scroll through each of them.



"Klatuu" wrote:

You can't use a multi select list box control as a bound control. It will
always return a Null value.
I'm not sure I understand the issue.

"BethHill" wrote:

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #7  
Old July 12th, 2006, 09:33 PM posted to microsoft.public.access.forms
BethHill
external usenet poster
 
Posts: 13
Default Multiple-select from list

The [Event ID] text is very meaningful to the user and is unique. (It is the
primary key in the "tbl Event" table.) There are currently about 100+
records or [Event ID]s that the user could choose from but could be more very
soon. If columns is not a good alternative, do you know of another option?

"Klatuu" wrote:

If you are talking about putting multiple [Event ID]s in the list box item (1
id per column), it is possible, but not easy, and would be difficult to
select. How would the user know which column to select? How would you, as
the developer, know which column to use? Is the [Event ID] text that is
meaningful to a user? Is it unique? How many are we talking about?

"BethHill" wrote:

Let me give you my scenario:

In the form, there is a multi-select list box with the control source as
"SELECT [tbl Event].[Event ID] FROM [tbl Event]; " This correctly displays
all the records for the Event ID field.

In this list box, there are many records that I have to scroll through in
order to select the ones that I want. I was wondering if there is a way to
display more records in the list box rather than scroll through each of them.



"Klatuu" wrote:

You can't use a multi select list box control as a bound control. It will
always return a Null value.
I'm not sure I understand the issue.

"BethHill" wrote:

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #8  
Old July 12th, 2006, 10:29 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Multiple-select from list

There is not a better solution that I can think of. I tried using a combo
with auto expand to position the list box, but anything previously selected
became unselected.

"BethHill" wrote:

The [Event ID] text is very meaningful to the user and is unique. (It is the
primary key in the "tbl Event" table.) There are currently about 100+
records or [Event ID]s that the user could choose from but could be more very
soon. If columns is not a good alternative, do you know of another option?

"Klatuu" wrote:

If you are talking about putting multiple [Event ID]s in the list box item (1
id per column), it is possible, but not easy, and would be difficult to
select. How would the user know which column to select? How would you, as
the developer, know which column to use? Is the [Event ID] text that is
meaningful to a user? Is it unique? How many are we talking about?

"BethHill" wrote:

Let me give you my scenario:

In the form, there is a multi-select list box with the control source as
"SELECT [tbl Event].[Event ID] FROM [tbl Event]; " This correctly displays
all the records for the Event ID field.

In this list box, there are many records that I have to scroll through in
order to select the ones that I want. I was wondering if there is a way to
display more records in the list box rather than scroll through each of them.



"Klatuu" wrote:

You can't use a multi select list box control as a bound control. It will
always return a Null value.
I'm not sure I understand the issue.

"BethHill" wrote:

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #9  
Old July 13th, 2006, 01:24 PM posted to microsoft.public.access.forms
BethHill
external usenet poster
 
Posts: 13
Default Multiple-select from list

Could I use something else, like a text box and have the user to sepearte the
choices with commas or do a range with a hyphen? Similar to print options
when selecting the pages to be printed. If so, do you have the code to do
this?

"Klatuu" wrote:

There is not a better solution that I can think of. I tried using a combo
with auto expand to position the list box, but anything previously selected
became unselected.

"BethHill" wrote:

The [Event ID] text is very meaningful to the user and is unique. (It is the
primary key in the "tbl Event" table.) There are currently about 100+
records or [Event ID]s that the user could choose from but could be more very
soon. If columns is not a good alternative, do you know of another option?

"Klatuu" wrote:

If you are talking about putting multiple [Event ID]s in the list box item (1
id per column), it is possible, but not easy, and would be difficult to
select. How would the user know which column to select? How would you, as
the developer, know which column to use? Is the [Event ID] text that is
meaningful to a user? Is it unique? How many are we talking about?

"BethHill" wrote:

Let me give you my scenario:

In the form, there is a multi-select list box with the control source as
"SELECT [tbl Event].[Event ID] FROM [tbl Event]; " This correctly displays
all the records for the Event ID field.

In this list box, there are many records that I have to scroll through in
order to select the ones that I want. I was wondering if there is a way to
display more records in the list box rather than scroll through each of them.



"Klatuu" wrote:

You can't use a multi select list box control as a bound control. It will
always return a Null value.
I'm not sure I understand the issue.

"BethHill" wrote:

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

  #10  
Old July 13th, 2006, 01:56 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Multiple-select from list

I guess you could, but I really think that would take more time and be more
prone to errors. Also, remember, you want to be able to select a range or
use ctlClick to select multiple noncontiguous items. You would not be able
to do that easily.

I really believe the multi select list box is the easiest to develop and
would be the most user friendly.

"BethHill" wrote:

Could I use something else, like a text box and have the user to sepearte the
choices with commas or do a range with a hyphen? Similar to print options
when selecting the pages to be printed. If so, do you have the code to do
this?

"Klatuu" wrote:

There is not a better solution that I can think of. I tried using a combo
with auto expand to position the list box, but anything previously selected
became unselected.

"BethHill" wrote:

The [Event ID] text is very meaningful to the user and is unique. (It is the
primary key in the "tbl Event" table.) There are currently about 100+
records or [Event ID]s that the user could choose from but could be more very
soon. If columns is not a good alternative, do you know of another option?

"Klatuu" wrote:

If you are talking about putting multiple [Event ID]s in the list box item (1
id per column), it is possible, but not easy, and would be difficult to
select. How would the user know which column to select? How would you, as
the developer, know which column to use? Is the [Event ID] text that is
meaningful to a user? Is it unique? How many are we talking about?

"BethHill" wrote:

Let me give you my scenario:

In the form, there is a multi-select list box with the control source as
"SELECT [tbl Event].[Event ID] FROM [tbl Event]; " This correctly displays
all the records for the Event ID field.

In this list box, there are many records that I have to scroll through in
order to select the ones that I want. I was wondering if there is a way to
display more records in the list box rather than scroll through each of them.



"Klatuu" wrote:

You can't use a multi select list box control as a bound control. It will
always return a Null value.
I'm not sure I understand the issue.

"BethHill" wrote:

Thank you! I am now able to make multiple selections in my list box. Now
the problem lies with the text that is in the list box. There is just field
for the control source on the list box but multiple of records. The field is
just an AutoNumber in the list box. I don't want to have to scroll down all
the way through the list to choose the records I want to send to SQL
statement. Is there a way to make it wrap the text by using columns in the
list box?

"Klatuu" wrote:

You will need a List Box control with the Multi Select property set to
Extended. This will allow you to use the familiar, Click to get one, Ctl
Click to add another, or Shift Click to select a range.

Now, you need a Row Source for the field. It should look something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

This will return one occurance of every value in the field.

Once the user has selected a field, you can use the ItemsSelected collection
of the List Box control to put together a where condition for your SQL
statement:

Dim varItem As Variant
Dim strWhere as String

strWhere = "IN("
For Each varItem In Me.MyListBoxName.ItemsSelected
strWhere = strWhere & Chr(34) & Me.MyListBoxName.ItemData(varItem) & _
Chr(34) & ","
Next varItem
'Take off the last comma
strWhere = Left(strWhere, Len(strWhere) -1)
'Add the closing paren
strWhere = strWhere & ")"

Now you have a string you can use in your SQL that will filter based on the
selections maked in the list box.

"BethHill" wrote:

Hello,

I want to be able to make multiple selections on my form from the same field
in the same table but allow specific records to be selected, as well as a
range of records and certain records (comma delimited?). After the fields
are selected, I want to pass this value into a SQL statement to perform the
query. How do I do this?

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:04 PM.


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