Adding "All" to a Combo Box

G

Guest

Hi,

I read somewhere that you can add a "All" option to a Combo box that will
display all records based on a particular field. I have a list of names and I
would like to have the option of displaying single individuals or all
individuals.

Can this be when I have the following:

Combo Box Name = cboStudentNames
Column Count = 2
Column Widths = 0";1"

RowSource is the following SQL statement

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
ORDER BY Students.S_Name;

-AKA
 
R

Ron Weiner

Change the Query to

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
UNION
SELECT -1, '[ALL]'
FROM Students
ORDER BY Students.S_Name;

This will cause the [ALL] to be the first student in the list (unless you
hapen to have some pretty weird student names). Now all you have to do is
to take care of the logic that handles the -1 differently than all of the
other student ID's I am assuming that the Student ID's are an autonumber
that started with a positive 1 as the first record.

Ron W
 
G

Guest

Hi Ron,

I'm having trouble trying to get things to work. When you said:
Now all you have to do is
to take care of the logic that handles the -1 differently than all of the
other student ID's I am assuming that the Student ID's are an autonumber
that started with a positive 1 as the first record.

The StudentID is a autonumber field, but I don't know how to handle the -1
part. When a name is selected from the Combo, the code in AfterUpdate opens a
report. So, should I do something in the report to handle -1 or handle the -1
in the AfterUpdate section.

-AKA



Ron Weiner said:
Change the Query to

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
UNION
SELECT -1, '[ALL]'
FROM Students
ORDER BY Students.S_Name;

This will cause the [ALL] to be the first student in the list (unless you
hapen to have some pretty weird student names). Now all you have to do is
to take care of the logic that handles the -1 differently than all of the
other student ID's I am assuming that the Student ID's are an autonumber
that started with a positive 1 as the first record.

Ron W

AKA Spawn said:
Hi,

I read somewhere that you can add a "All" option to a Combo box that will
display all records based on a particular field. I have a list of names and I
would like to have the option of displaying single individuals or all
individuals.

Can this be when I have the following:

Combo Box Name = cboStudentNames
Column Count = 2
Column Widths = 0";1"

RowSource is the following SQL statement

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
ORDER BY Students.S_Name;

-AKA
 
R

Ron Weiner

Change the code in the AfterUpdate Event do something like

If cboStudentNames.value = -1 then
' Do what ever you want the to do when the user selects "All"
' Perhaps changing the record source of the form to remove
' itsWHERE condition so all of the records are available
Else
' Do that same thing you are doing now
End IF

Ron W

AKA Spawn said:
Hi Ron,

I'm having trouble trying to get things to work. When you said:
Now all you have to do is
to take care of the logic that handles the -1 differently than all of the
other student ID's I am assuming that the Student ID's are an autonumber
that started with a positive 1 as the first record.

The StudentID is a autonumber field, but I don't know how to handle the -1
part. When a name is selected from the Combo, the code in AfterUpdate opens a
report. So, should I do something in the report to handle -1 or handle the -1
in the AfterUpdate section.

-AKA



Ron Weiner said:
Change the Query to

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
UNION
SELECT -1, '[ALL]'
FROM Students
ORDER BY Students.S_Name;

This will cause the [ALL] to be the first student in the list (unless you
hapen to have some pretty weird student names). Now all you have to do is
to take care of the logic that handles the -1 differently than all of the
other student ID's I am assuming that the Student ID's are an autonumber
that started with a positive 1 as the first record.

Ron W

AKA Spawn said:
Hi,

I read somewhere that you can add a "All" option to a Combo box that will
display all records based on a particular field. I have a list of
names
and I
would like to have the option of displaying single individuals or all
individuals.

Can this be when I have the following:

Combo Box Name = cboStudentNames
Column Count = 2
Column Widths = 0";1"

RowSource is the following SQL statement

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
ORDER BY Students.S_Name;

-AKA
 
G

Guest

Ron,

Awesome dude, thanks a million for your help with this because I was totally
lost.

-AKA

Ron Weiner said:
Change the code in the AfterUpdate Event do something like

If cboStudentNames.value = -1 then
' Do what ever you want the to do when the user selects "All"
' Perhaps changing the record source of the form to remove
' itsWHERE condition so all of the records are available
Else
' Do that same thing you are doing now
End IF

Ron W

AKA Spawn said:
Hi Ron,

I'm having trouble trying to get things to work. When you said:
Now all you have to do is
to take care of the logic that handles the -1 differently than all of the
other student ID's I am assuming that the Student ID's are an autonumber
that started with a positive 1 as the first record.

The StudentID is a autonumber field, but I don't know how to handle the -1
part. When a name is selected from the Combo, the code in AfterUpdate opens a
report. So, should I do something in the report to handle -1 or handle the -1
in the AfterUpdate section.

-AKA



Ron Weiner said:
Change the Query to

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
UNION
SELECT -1, '[ALL]'
FROM Students
ORDER BY Students.S_Name;

This will cause the [ALL] to be the first student in the list (unless you
hapen to have some pretty weird student names). Now all you have to do is
to take care of the logic that handles the -1 differently than all of the
other student ID's I am assuming that the Student ID's are an autonumber
that started with a positive 1 as the first record.

Ron W

Hi,

I read somewhere that you can add a "All" option to a Combo box that will
display all records based on a particular field. I have a list of names
and I
would like to have the option of displaying single individuals or all
individuals.

Can this be when I have the following:

Combo Box Name = cboStudentNames
Column Count = 2
Column Widths = 0";1"

RowSource is the following SQL statement

SELECT DISTINCT Students.StudentID, Students.S_Name
FROM Students
ORDER BY Students.S_Name;

-AKA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top