More problems with Multiselect List Boxes

C

Chris

I can't get this list box to work with more than one choice. It works as
planned for one choice, but not more than one. Can someone take a quick look
& see what the deal is? Here's what I have:


Private Sub OkCmd_Click()

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String, strWHERE As String

Set frm = Me.Form
Set ctl = Me.lstLevel

For Each varItem In ctl.ItemsSelected
If Len(strSQL) = 0 Then
strSQL = strSQL & "*" & ctl.ItemData(varItem) & "*"
Else
strSQL = strSQL & " OR ([Employee List].Level) Like " & "*" &
ctl.ItemData(varItem) & "*"
End If
Next varItem

Me.txtstrSQL = strSQL

End Sub
 
C

Chris

The criteria in my query is:
Like [Forms]![frmLevelSelect]![txtstrSQL]

And like I said, the multi-select box works for 1 option, but not more than
1???
 
A

a

I have struggled with the same problem in the past.
From my opinion it is best to avoid using the ItemsSelected property.
When I need to collect multiple selected items, I use the Selected property.
Loop through all the items in your list and check if the item is selected
with the Selected(x) property.
If it returns True, then the item is selected.

John.

Chris said:
The criteria in my query is:
Like [Forms]![frmLevelSelect]![txtstrSQL]

And like I said, the multi-select box works for 1 option, but not more than
1???

Chris said:
I can't get this list box to work with more than one choice. It works as
planned for one choice, but not more than one. Can someone take a quick look
& see what the deal is? Here's what I have:


Private Sub OkCmd_Click()

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String, strWHERE As String

Set frm = Me.Form
Set ctl = Me.lstLevel

For Each varItem In ctl.ItemsSelected
If Len(strSQL) = 0 Then
strSQL = strSQL & "*" & ctl.ItemData(varItem) & "*"
Else
strSQL = strSQL & " OR ([Employee List].Level) Like " & "*" &
ctl.ItemData(varItem) & "*"
End If
Next varItem

Me.txtstrSQL = strSQL

End Sub
 
D

Dirk Goldgar

Chris said:
The criteria in my query is:
Like [Forms]![frmLevelSelect]![txtstrSQL]

And like I said, the multi-select box works for 1 option, but not
more than 1???

Chris said:
I can't get this list box to work with more than one choice. It
works as planned for one choice, but not more than one. Can someone
take a quick look & see what the deal is? Here's what I have:


Private Sub OkCmd_Click()

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String, strWHERE As String

Set frm = Me.Form
Set ctl = Me.lstLevel

For Each varItem In ctl.ItemsSelected
If Len(strSQL) = 0 Then
strSQL = strSQL & "*" & ctl.ItemData(varItem) & "*"
Else
strSQL = strSQL & " OR ([Employee List].Level) Like " & "*" &
ctl.ItemData(varItem) & "*"
End If
Next varItem

Me.txtstrSQL = strSQL

End Sub

That approach won't work, because the query won't interpret the
expression "Like [Forms]![frmLevelSelect]![txtstrSQL]" the way you want.
It will look at the value of the text box as the simple, literal pattern
you're trying to match against, not as an extension of the SQL statement
itself.

Your best bet in cases like this is to build the whole SQL statement for
your query in code. Then you can incorporate the criteria string you've
built directly into the SQL statement itself. That means, though, that
you can't just use a stored query; if you use a stored query, you have
to modify its SQL (stuffing the SQL statement you've built into it)
before executing the query. However, usually you can avoid using a
stored query, and just assign the constructed SQL statement to the
recordsource of a form or report, or the rowsource of a combo or list
box, in the appropriate event. If you post more details about what
you're trying to accomplish, we may be able to advise you.
 
C

Chris

Right now, these reports/queries are set up to each prompt with more than a
dozen different parameter queries for each of the employee levels we have...
"Show Employees Level 1 (Y or N)?" "Show Employees Level 2 (Y or N)?" "Show
Employees Level 3 (Y or N)?" 4...5...6...7...etc, etc.

So you go through each prompt & answer with Y or N for every employee
level!!! The end result is the same, but this is definitely not convenient
or very user-friendly. Thus, I need a simple multi-select list box.

What I want is that when I open a report, this form pops up with a
multi-select box asking which "employee levels" I want in the report, the
query runs, and the report generates (without having to Y/N through a dozen
plus prompts). Also, i want to use this same form for several different
reports & queries where I'd like to have the option of picking 1 or more
different "employee levels", so I don't want to set the multi-select box to
one particular query.

Also, I'm beginner-level in access....LOL


Dirk Goldgar said:
Chris said:
The criteria in my query is:
Like [Forms]![frmLevelSelect]![txtstrSQL]

And like I said, the multi-select box works for 1 option, but not
more than 1???

Chris said:
I can't get this list box to work with more than one choice. It
works as planned for one choice, but not more than one. Can someone
take a quick look & see what the deal is? Here's what I have:


Private Sub OkCmd_Click()

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String, strWHERE As String

Set frm = Me.Form
Set ctl = Me.lstLevel

For Each varItem In ctl.ItemsSelected
If Len(strSQL) = 0 Then
strSQL = strSQL & "*" & ctl.ItemData(varItem) & "*"
Else
strSQL = strSQL & " OR ([Employee List].Level) Like " & "*" &
ctl.ItemData(varItem) & "*"
End If
Next varItem

Me.txtstrSQL = strSQL

End Sub

That approach won't work, because the query won't interpret the
expression "Like [Forms]![frmLevelSelect]![txtstrSQL]" the way you want.
It will look at the value of the text box as the simple, literal pattern
you're trying to match against, not as an extension of the SQL statement
itself.

Your best bet in cases like this is to build the whole SQL statement for
your query in code. Then you can incorporate the criteria string you've
built directly into the SQL statement itself. That means, though, that
you can't just use a stored query; if you use a stored query, you have
to modify its SQL (stuffing the SQL statement you've built into it)
before executing the query. However, usually you can avoid using a
stored query, and just assign the constructed SQL statement to the
recordsource of a form or report, or the rowsource of a combo or list
box, in the appropriate event. If you post more details about what
you're trying to accomplish, we may be able to advise you.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
T

TonyT

Hi Chris,

I've muddled around with something not too dissimilar in the past and failed
to find an easy way of acheiving it, as a suggested the Selected property was
my chosen route, but I ended up (rather long windedly) assigning values
1,2,4,8,16,32,64,128 etc etc to the numbers in a hidden column and added the
values, and then dis-assembled them with code to create the report, depending
on the originating form.

but then i'm not very good at vba and worse with SQL so went for my usual
'brute force' approach!!!

TonyT


Chris said:
Right now, these reports/queries are set up to each prompt with more than a
dozen different parameter queries for each of the employee levels we have...
"Show Employees Level 1 (Y or N)?" "Show Employees Level 2 (Y or N)?" "Show
Employees Level 3 (Y or N)?" 4...5...6...7...etc, etc.

So you go through each prompt & answer with Y or N for every employee
level!!! The end result is the same, but this is definitely not convenient
or very user-friendly. Thus, I need a simple multi-select list box.

What I want is that when I open a report, this form pops up with a
multi-select box asking which "employee levels" I want in the report, the
query runs, and the report generates (without having to Y/N through a dozen
plus prompts). Also, i want to use this same form for several different
reports & queries where I'd like to have the option of picking 1 or more
different "employee levels", so I don't want to set the multi-select box to
one particular query.

Also, I'm beginner-level in access....LOL


Dirk Goldgar said:
Chris said:
The criteria in my query is:
Like [Forms]![frmLevelSelect]![txtstrSQL]

And like I said, the multi-select box works for 1 option, but not
more than 1???

:

I can't get this list box to work with more than one choice. It
works as planned for one choice, but not more than one. Can someone
take a quick look & see what the deal is? Here's what I have:


Private Sub OkCmd_Click()

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String, strWHERE As String

Set frm = Me.Form
Set ctl = Me.lstLevel

For Each varItem In ctl.ItemsSelected
If Len(strSQL) = 0 Then
strSQL = strSQL & "*" & ctl.ItemData(varItem) & "*"
Else
strSQL = strSQL & " OR ([Employee List].Level) Like " & "*" &
ctl.ItemData(varItem) & "*"
End If
Next varItem

Me.txtstrSQL = strSQL

End Sub

That approach won't work, because the query won't interpret the
expression "Like [Forms]![frmLevelSelect]![txtstrSQL]" the way you want.
It will look at the value of the text box as the simple, literal pattern
you're trying to match against, not as an extension of the SQL statement
itself.

Your best bet in cases like this is to build the whole SQL statement for
your query in code. Then you can incorporate the criteria string you've
built directly into the SQL statement itself. That means, though, that
you can't just use a stored query; if you use a stored query, you have
to modify its SQL (stuffing the SQL statement you've built into it)
before executing the query. However, usually you can avoid using a
stored query, and just assign the constructed SQL statement to the
recordsource of a form or report, or the rowsource of a combo or list
box, in the appropriate event. If you post more details about what
you're trying to accomplish, we may be able to advise you.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Chris said:
Right now, these reports/queries are set up to each prompt with more
than a dozen different parameter queries for each of the employee
levels we have... "Show Employees Level 1 (Y or N)?" "Show Employees
Level 2 (Y or N)?" "Show Employees Level 3 (Y or N)?"
4...5...6...7...etc, etc.

So you go through each prompt & answer with Y or N for every employee
level!!! The end result is the same, but this is definitely not
convenient or very user-friendly. Thus, I need a simple multi-select
list box.

What I want is that when I open a report, this form pops up with a
multi-select box asking which "employee levels" I want in the report,
the query runs, and the report generates (without having to Y/N
through a dozen plus prompts). Also, i want to use this same form
for several different reports & queries where I'd like to have the
option of picking 1 or more different "employee levels", so I don't
want to set the multi-select box to one particular query.

Also, I'm beginner-level in access....LOL

That's going to make it a bit harder to get where you want to go, but we
can get there if you're patient. This is what I recommend as an overall
approach:

===============
1. Create a dialog form that contains the list box and a public function
that returns the criteria string for the employee level (details on the
function to be supplied below). You can use your existing form,
"frmLevelSelect", for this purpose, but you'll need to modify it. Set
this form up so that it has an OK button that hides the form (by setting
its Visible property to False), and a Cancel button that just closes the
form.

2. Base the relevant reports or forms on a query that doesn't apply any
criteria to the employee level field.

3. In the Open event for each such report, open frmLevelSelect in dialog
mode. That will pause the code in the Open event until the form is
either hidden (the user clicked OK) or closed (the user clicked Cancel).
So, in the report's Open event, when execution resumes after opening the
form, check to see if the form is still open (hidden). If it is, call
the function on the form that returns the criteria string derived from
the list box, and append that to the report's recordsource query,
updating the recordsource.
===============

Here's code for the code module of frmLevelSelect, based on what you
already wrote. I'm going to take the liberty of changing the "Like '*'
& ctl.ItemData(varItem) & '*'" expressions that you've written to plain
tests for equality, but we can go back to something more like your
original code if that's necessary. I'm also going to assume that the
employee-level field is numeric, not text.

'------ start of code for frmLevelSelect ------
Public Function FilterCriteria() As String

Dim varItem As Variant
Dim strCriteria As String

With Me!lstLevel
For Each varItem In .ItemsSelected
strCriteria = strCriteria & ", " & ItemData(varItem)
Next varItem

If Len(strCriteria) > 0 Then
strCriteria = Mid$(strCriteria, 3) ' drop leading ", "
If .ItemsSelected.Count = 1 Then
strCriteria = _
"([Employee List].Level=" & strCriteria & ")"
Else
strCriteria = _
"([Employee List].Level In (" & strCriteria & "))"
End If
End If
End With

FilterCriteria = strCriteria

End Function

Private Sub OkCmd_Click()

Me.Visible = False

End Sub

Private Sub CancelCmd_Click()

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
'------ end of code for frmLevelSelect ------

Here's sample code for the Open event of a report that wants to use this
form:

'------ start of example report code ------
Private Sub Report_Open(Cancel As Integer)

Dim strRecordSource As String
Dim strCriteria As String

DoCmd.OpenForm "frmLevelSelect", _
WindowMode:=acDialog

If CurrentProject.AllForms("frmLevelSelect").IsLoaded Then
strCriteria = Forms!frmLevelSelect.FilterCriteria()
DoCmd.Close acForm, "frmLevelSelect", acSaveNo
End If

If Len(strCriteria) > 0 Then
strRecordSource = Me.RecordSource
If Left(strRecordSource, 6) <> "SELECT" Then
strRecordSource = _
"SELECT * FROM [" & strRecordSource & _
"] WHERE " & strCriteria
Else
If Right(strRecordSource, 1) = ";" Then
strRecordSource = _
Left(strRecordSource, Len(strRecordSource) - 1)
End If
If InStr(strRecordSource, " WHERE ") > 0 Then
strRecordSource = _
strRecordSource & " AND " & strCriteria
Else
strRecordSource = _
strRecordSource & " WHERE " & strCriteria
End If
End If

Me.RecordSource = strRecordSource

End If

End Sub
'------ end of example report code ------

Note that the above is all "air code", and that it won't work right if,
for example, the report's recordsource contains an ORDER BY clause. But
reports normally do their own sorting, so an ORDER BY clause is seldom
necessary in a report's recordsource query. More elaborate code could
be used to cope with a wider variety of recordsource queries.
 
C

Chris

Dirk,

I've looked at what you wrote, and when I run it I get some errors.

Compile Error: Variable not Defined
on line that reads If
CurrentProject.AllForms("frmLevelSelect").IsLoaded Then
(please note I'm using Access '97).

Compile Error: Sub or Function not Defined
on line that reads strCriteria = strCriteria & ", " &
ItemData(varItem)

I'll fiddle around & see if I can get anything, thank you much for the help


Dirk Goldgar said:
Chris said:
Right now, these reports/queries are set up to each prompt with more
than a dozen different parameter queries for each of the employee
levels we have... "Show Employees Level 1 (Y or N)?" "Show Employees
Level 2 (Y or N)?" "Show Employees Level 3 (Y or N)?"
4...5...6...7...etc, etc.

So you go through each prompt & answer with Y or N for every employee
level!!! The end result is the same, but this is definitely not
convenient or very user-friendly. Thus, I need a simple multi-select
list box.

What I want is that when I open a report, this form pops up with a
multi-select box asking which "employee levels" I want in the report,
the query runs, and the report generates (without having to Y/N
through a dozen plus prompts). Also, i want to use this same form
for several different reports & queries where I'd like to have the
option of picking 1 or more different "employee levels", so I don't
want to set the multi-select box to one particular query.

Also, I'm beginner-level in access....LOL

That's going to make it a bit harder to get where you want to go, but we
can get there if you're patient. This is what I recommend as an overall
approach:

===============
1. Create a dialog form that contains the list box and a public function
that returns the criteria string for the employee level (details on the
function to be supplied below). You can use your existing form,
"frmLevelSelect", for this purpose, but you'll need to modify it. Set
this form up so that it has an OK button that hides the form (by setting
its Visible property to False), and a Cancel button that just closes the
form.

2. Base the relevant reports or forms on a query that doesn't apply any
criteria to the employee level field.

3. In the Open event for each such report, open frmLevelSelect in dialog
mode. That will pause the code in the Open event until the form is
either hidden (the user clicked OK) or closed (the user clicked Cancel).
So, in the report's Open event, when execution resumes after opening the
form, check to see if the form is still open (hidden). If it is, call
the function on the form that returns the criteria string derived from
the list box, and append that to the report's recordsource query,
updating the recordsource.
===============

Here's code for the code module of frmLevelSelect, based on what you
already wrote. I'm going to take the liberty of changing the "Like '*'
& ctl.ItemData(varItem) & '*'" expressions that you've written to plain
tests for equality, but we can go back to something more like your
original code if that's necessary. I'm also going to assume that the
employee-level field is numeric, not text.

'------ start of code for frmLevelSelect ------
Public Function FilterCriteria() As String

Dim varItem As Variant
Dim strCriteria As String

With Me!lstLevel
For Each varItem In .ItemsSelected
strCriteria = strCriteria & ", " & ItemData(varItem)
Next varItem

If Len(strCriteria) > 0 Then
strCriteria = Mid$(strCriteria, 3) ' drop leading ", "
If .ItemsSelected.Count = 1 Then
strCriteria = _
"([Employee List].Level=" & strCriteria & ")"
Else
strCriteria = _
"([Employee List].Level In (" & strCriteria & "))"
End If
End If
End With

FilterCriteria = strCriteria

End Function

Private Sub OkCmd_Click()

Me.Visible = False

End Sub

Private Sub CancelCmd_Click()

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
'------ end of code for frmLevelSelect ------

Here's sample code for the Open event of a report that wants to use this
form:

'------ start of example report code ------
Private Sub Report_Open(Cancel As Integer)

Dim strRecordSource As String
Dim strCriteria As String

DoCmd.OpenForm "frmLevelSelect", _
WindowMode:=acDialog

If CurrentProject.AllForms("frmLevelSelect").IsLoaded Then
strCriteria = Forms!frmLevelSelect.FilterCriteria()
DoCmd.Close acForm, "frmLevelSelect", acSaveNo
End If

If Len(strCriteria) > 0 Then
strRecordSource = Me.RecordSource
If Left(strRecordSource, 6) <> "SELECT" Then
strRecordSource = _
"SELECT * FROM [" & strRecordSource & _
"] WHERE " & strCriteria
Else
If Right(strRecordSource, 1) = ";" Then
strRecordSource = _
Left(strRecordSource, Len(strRecordSource) - 1)
End If
If InStr(strRecordSource, " WHERE ") > 0 Then
strRecordSource = _
strRecordSource & " AND " & strCriteria
Else
strRecordSource = _
strRecordSource & " WHERE " & strCriteria
End If
End If

Me.RecordSource = strRecordSource

End If

End Sub
'------ end of example report code ------

Note that the above is all "air code", and that it won't work right if,
for example, the report's recordsource contains an ORDER BY clause. But
reports normally do their own sorting, so an ORDER BY clause is seldom
necessary in a report's recordsource query. More elaborate code could
be used to cope with a wider variety of recordsource queries.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Chris said:
Dirk,

I've looked at what you wrote, and when I run it I get some errors.

Compile Error: Variable not Defined
on line that reads If
CurrentProject.AllForms("frmLevelSelect").IsLoaded Then
(please note I'm using Access '97).

Ah, if you mentioned that, I overlooked it. In that case you can't use
the CurrentProject methods and properties, because they were introduced
in Access 2000. You'll need this function, which was originally
provided by Microsoft in one of their sample databases and has been
widely posted:

'----- start of code -----
Function IsLoaded(ObjectName As String, _
Optional ObjectType As Integer = acForm) _
As Boolean

If SysCmd(acSysCmdGetObjectState, ObjectType, ObjectName) _
= acObjStateOpen _
Then
Select Case ObjectType
Case acForm
If Forms(ObjectName).CurrentView <> 0 Then
IsLoaded = True
End If
Case Else
IsLoaded = True
End Select
End If

End Function
'----- end of code -----

Paste that code into a standard module (an existing one, or create a new
standard module if you like -- but don't name the module "IsLoaded").
Then change the line of code I originally posted:
If CurrentProject.AllForms("frmLevelSelect").IsLoaded Then

to this:

If IsLoaded("frmLevelSelect") Then
Compile Error: Sub or Function not Defined
on line that reads strCriteria = strCriteria & ", " &
ItemData(varItem)

I made a typo there: left off the leading period from ItemData.
Instead of this:
strCriteria = strCriteria & ", " & ItemData(varItem)

use this:

strCriteria = strCriteria & ", " & .ItemData(varItem)

Sorry about that. I did say it was air code.
 
C

Chris

Also, the employee-level field is not numeric, they're full employee titles.


Dirk Goldgar said:
Chris said:
Right now, these reports/queries are set up to each prompt with more
than a dozen different parameter queries for each of the employee
levels we have... "Show Employees Level 1 (Y or N)?" "Show Employees
Level 2 (Y or N)?" "Show Employees Level 3 (Y or N)?"
4...5...6...7...etc, etc.

So you go through each prompt & answer with Y or N for every employee
level!!! The end result is the same, but this is definitely not
convenient or very user-friendly. Thus, I need a simple multi-select
list box.

What I want is that when I open a report, this form pops up with a
multi-select box asking which "employee levels" I want in the report,
the query runs, and the report generates (without having to Y/N
through a dozen plus prompts). Also, i want to use this same form
for several different reports & queries where I'd like to have the
option of picking 1 or more different "employee levels", so I don't
want to set the multi-select box to one particular query.

Also, I'm beginner-level in access....LOL

That's going to make it a bit harder to get where you want to go, but we
can get there if you're patient. This is what I recommend as an overall
approach:

===============
1. Create a dialog form that contains the list box and a public function
that returns the criteria string for the employee level (details on the
function to be supplied below). You can use your existing form,
"frmLevelSelect", for this purpose, but you'll need to modify it. Set
this form up so that it has an OK button that hides the form (by setting
its Visible property to False), and a Cancel button that just closes the
form.

2. Base the relevant reports or forms on a query that doesn't apply any
criteria to the employee level field.

3. In the Open event for each such report, open frmLevelSelect in dialog
mode. That will pause the code in the Open event until the form is
either hidden (the user clicked OK) or closed (the user clicked Cancel).
So, in the report's Open event, when execution resumes after opening the
form, check to see if the form is still open (hidden). If it is, call
the function on the form that returns the criteria string derived from
the list box, and append that to the report's recordsource query,
updating the recordsource.
===============

Here's code for the code module of frmLevelSelect, based on what you
already wrote. I'm going to take the liberty of changing the "Like '*'
& ctl.ItemData(varItem) & '*'" expressions that you've written to plain
tests for equality, but we can go back to something more like your
original code if that's necessary. I'm also going to assume that the
employee-level field is numeric, not text.

'------ start of code for frmLevelSelect ------
Public Function FilterCriteria() As String

Dim varItem As Variant
Dim strCriteria As String

With Me!lstLevel
For Each varItem In .ItemsSelected
strCriteria = strCriteria & ", " & ItemData(varItem)
Next varItem

If Len(strCriteria) > 0 Then
strCriteria = Mid$(strCriteria, 3) ' drop leading ", "
If .ItemsSelected.Count = 1 Then
strCriteria = _
"([Employee List].Level=" & strCriteria & ")"
Else
strCriteria = _
"([Employee List].Level In (" & strCriteria & "))"
End If
End If
End With

FilterCriteria = strCriteria

End Function

Private Sub OkCmd_Click()

Me.Visible = False

End Sub

Private Sub CancelCmd_Click()

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
'------ end of code for frmLevelSelect ------

Here's sample code for the Open event of a report that wants to use this
form:

'------ start of example report code ------
Private Sub Report_Open(Cancel As Integer)

Dim strRecordSource As String
Dim strCriteria As String

DoCmd.OpenForm "frmLevelSelect", _
WindowMode:=acDialog

If CurrentProject.AllForms("frmLevelSelect").IsLoaded Then
strCriteria = Forms!frmLevelSelect.FilterCriteria()
DoCmd.Close acForm, "frmLevelSelect", acSaveNo
End If

If Len(strCriteria) > 0 Then
strRecordSource = Me.RecordSource
If Left(strRecordSource, 6) <> "SELECT" Then
strRecordSource = _
"SELECT * FROM [" & strRecordSource & _
"] WHERE " & strCriteria
Else
If Right(strRecordSource, 1) = ";" Then
strRecordSource = _
Left(strRecordSource, Len(strRecordSource) - 1)
End If
If InStr(strRecordSource, " WHERE ") > 0 Then
strRecordSource = _
strRecordSource & " AND " & strCriteria
Else
strRecordSource = _
strRecordSource & " WHERE " & strCriteria
End If
End If

Me.RecordSource = strRecordSource

End If

End Sub
'------ end of example report code ------

Note that the above is all "air code", and that it won't work right if,
for example, the report's recordsource contains an ORDER BY clause. But
reports normally do their own sorting, so an ORDER BY clause is seldom
necessary in a report's recordsource query. More elaborate code could
be used to cope with a wider variety of recordsource queries.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Chris said:
Also, the employee-level field is not numeric, they're full employee
titles.

In that case, you need to change this line:
strCriteria = strCriteria & ", " & ItemData(varItem)

to this:

strCriteria = strCriteria & ", '" & ItemData(varItem) & "'"

Spacing it out a bit for readability (but don't do this in your code),
that's

strCriteria = strCriteria & ", ' " & ItemData(varItem) & " ' "

So each level selected is enclosed in single-quotes ('). I'm assuming
that you don't have the single-quote character itself in your employee
level names; that would add another level of complexity I hope we can
avoid.
 

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