Is this a Quotes problem?

M

malgoro

I hate to bother for something that must be very simple, but I give up...I
need help:

I have a Parameter Query; the parameter is selected from a list box (list80)
on a form. The options on the list box are "ch", "wr" and "combined", where
"combined" should bring the combination of both "ch" and "wr".

This is my code, but it doesn't work when it comes to the "combined" option:

Private Sub List80_Change()

Dim strch As String
Dim strwr As String

strch = "ch"
strwr = "wr"

If List80.Value = "Combined" Then
List80.Value = "'" & strch & "'" & " or " & "'" & strwr & "'"
End If
End Sub

the characters are:
doublequotes_singlequote_doublequotes_space_ampersand_space_strch.... ...
....doublequotes_singlequote_doublequotes_space_ampersand_space_strwr_space_ampersand_space_doublequotes_singlequotes_doublequotes

After this, of course I click on a button that generates the report that's
based on the parameter query, but as I said, it doesn't show anything when it
comes to the combined option.

Thank you!
 
M

Mike Painter

malgoro said:
I hate to bother for something that must be very simple, but I give
up...I need help:

I have a Parameter Query; the parameter is selected from a list box
(list80) on a form. The options on the list box are "ch", "wr" and
"combined", where "combined" should bring the combination of both
"ch" and "wr".

This is my code, but it doesn't work when it comes to the "combined"
option:

Private Sub List80_Change()

Dim strch As String
Dim strwr As String

strch = "ch"
strwr = "wr"

If List80.Value = "Combined" Then
List80.Value = "'" & strch & "'" & " or " & "'" & strwr & "'"

Either "ch & wr"
or strch & "&" & strwr
Access does not recognize a variable if it is in quotes.
 
M

malgoro

Maybe i didn't make myself clear enough: the possible values of the filtered
field are CH or WR, so my guess is that the combined parameter should end up
being
"ch" or "wr"

in order for it to show both types of records; those with WR and those with
CH.

Your "ch & wr" will not show anything either.

Any other advise?

Thanks
 
J

John W. Vinson

Maybe i didn't make myself clear enough: the possible values of the filtered
field are CH or WR, so my guess is that the combined parameter should end up
being
"ch" or "wr"

in order for it to show both types of records; those with WR and those with
CH.

Your "ch & wr" will not show anything either.

Any other advise?

You can't pass an operator such as OR in the filter string. Try a criterion of

=[Forms]![YourFormName]![List80] OR [Forms]![YourFormName]![List80] =
"combined"

if you want all records retrieved for "combined"; or

=[Forms]![YourFormName]![List80] OR ([Forms]![YourFormName]![List80] =
"combined" AND [fieldname] IN ("ch", "wr"))

if you want only ch or wr records returned for "combined".
 
M

malgoro

Thanks John,

So what you're saying is that it is impossible to pass from a form to a
paramater query paramaters such as "black" OR "white" or "ch" OR
"wr", etc? There is no way around that?

Thanks again.

John W. Vinson said:
Maybe i didn't make myself clear enough: the possible values of the filtered
field are CH or WR, so my guess is that the combined parameter should end up
being
"ch" or "wr"

in order for it to show both types of records; those with WR and those with
CH.

Your "ch & wr" will not show anything either.

Any other advise?

You can't pass an operator such as OR in the filter string. Try a criterion of

=[Forms]![YourFormName]![List80] OR [Forms]![YourFormName]![List80] =
"combined"

if you want all records retrieved for "combined"; or

=[Forms]![YourFormName]![List80] OR ([Forms]![YourFormName]![List80] =
"combined" AND [fieldname] IN ("ch", "wr"))

if you want only ch or wr records returned for "combined".
 
M

malgoro

Hi again,

In addition to my prior question, Is it also impossible to send parameters
such as "in("wr", "ch")" or "like "*"" ???

thanks

John W. Vinson said:
Maybe i didn't make myself clear enough: the possible values of the filtered
field are CH or WR, so my guess is that the combined parameter should end up
being
"ch" or "wr"

in order for it to show both types of records; those with WR and those with
CH.

Your "ch & wr" will not show anything either.

Any other advise?

You can't pass an operator such as OR in the filter string. Try a criterion of

=[Forms]![YourFormName]![List80] OR [Forms]![YourFormName]![List80] =
"combined"

if you want all records retrieved for "combined"; or

=[Forms]![YourFormName]![List80] OR ([Forms]![YourFormName]![List80] =
"combined" AND [fieldname] IN ("ch", "wr"))

if you want only ch or wr records returned for "combined".
 
J

John W. Vinson

Hi again,

In addition to my prior question, Is it also impossible to send parameters
such as "in("wr", "ch")" or "like "*"" ???

Correct to both questions. It *is* impossible to pass operators in query
parameters, only search values. You'll need to construct a SQL string in code
if you want that flexibility.
 
M

malgoro

That's too bad :(

I'll build different queries according to those parameters.

Thanks you very much.
 

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

Similar Threads

OpenArgs and unwanted Parameter Boxes 2
Access Not Responding when VBA Code Run 3
Type Mismatch 0
go to specific record in form 2
Access Can't Get Dlookup To Work 1
MsgBox 7
Make default value "real" 4
me.filter small problem 1

Top