Well, I'm just at the end of my rope with this problem. I tried Fred's
solutions with no luck, and took your advice about going with String only.
The TRUE has always worked fine, and the report proiperly displays ONLY
the YarnID on the form.
The FALSE fails in every way I've tried to work it with the same error:
Perhaps it woulkd help to restate the setup...
1. YarnID is an unbound combo box on frmYarnPOsDialog that gets it
value
from [YarnID] a Num/Integer field.
2. YarnIDString : CStr([YarnID]) is calculated field in my report query
If user selects 709 in YarnID combo I need to allow 3 possible criteria
1. If chkThisIDOnly = True then report on ONLY on YarnID = 709
2. If chkThisIDOnly = False then report on YarnID 709, 7091, 7092,
etc...
3. If User leaves YarnID Null then report on ALL YarnIDs
My Code:
Dim YarnIDArg As String
Dim strYarnID As String
strYarnID = CStr(Me.YarnID)
If Me.chkThisIDOnly = True Then
YarnIDArg = "YarnIDString = " & strYarnID
ElseIf Me.chkThisIDOnly = False Then
YarnIDArg = "YarnIDString Like " & strYarnID & "*"
End If
DoCmd.OpenReport "rptYarnPosByYarnID", acViewPreview, , YarnIDArg
I'm stuck. I can't figure out what the heck is wrong with this code, or
some of the other coding I've tried. I think that is bogus, and there's
something else amiss other than just "syntax".
Thanks for any help,
Al Camp
Chaim said:
LIKE won't work on numbers. It is strictly a text string operator.
One option might be to convert each of your numeric fields to strings
(use
something like CStr()) and then use LIKE on these strings. For example,
SELECT CStr([A Numeric Field]) as StringNumber FROM YourTable
WHERE StringNumber LIKE StringNumber & "*";
Good Luck!
--
Chaim
Roger L said:
On Tue, 19 Jul 2005 20:07:28 -0400, Roger L wrote:
I'm trying to open a report from a form, and set up a "Where"
statement
for that OpenReport command.
If a checkbox is True, then use the exact value from a form field as
a
criteria.
If a checkbox is False, then use a Like * operators to return all
records
with
the field value, and any others that may qualify.
Roger
What is the datatype of [YarnID]?
If [YarnID] is a Number datatype then:
Dim YarnIDArg As String
If Me.chkThisIDOnly = True Then
YarnIDArg = "YarnID = " & Forms!frmYarnPOsDialog!YarnID
Else
YarnIDArg = "YarnID Like " & Forms!frmYarnPOsDialog!YarnID & "*"
End If
DoCmd.OpenReport "rptYarnPosByYarnID", acViewPreview, , YarnIDArg
If the above code is being run on the form frmYarnPOsDialog then use
the Me keyword instead:
YarnIDArg = "YarnID = " & Me!YarnID
Else
YarnIDArg = "YarnID Like " & Me!YarnID & "*"
However, if [YarnID] is Text datatype, then use:
YarnIDArg = "YarnID = '" & Me!YarnID & "'"
Else
YarnIDArg = "YarnID Like '" & Me!YarnID & "'*"
Fred
-----------------------------------------------------
Fred,
Thanks very much for your help.
I copied your code verbatim, but when the check box was False the code
failed with...
Run Time Error '3705'
Extra ) in Query Expression '(YarnID Like 709*)'
YarnID on the form is from an unbound combo box based on the YarnID
Numeric
Integer field.
Here's the code... cut and pasted
(ex. YarnID = 709, to yield 709, 7091, 7092 etc.)
Private Sub cmdYarnPOsByYarnID_Click()
Dim YarnIDArg As String
If Me.chkThisIDOnly = True Then
YarnIDArg = "YarnID = " & Me!YarnID
Else
YarnIDArg = "YarnID Like " & Me!YarnID & "*"
End If
DoCmd.OpenReport "rptYarnPosByYarnID", acViewPreview, , YarnIDArg
End Sub
I don't see anything wrong with your code!
Even the error message appears to display the correct syntax for the
argument. The True works fine.
A breakpoint on the False indicates (Me!YarnID = 709)
I hope I'm not going whacky here... but I can't see the problem.
Thanks for your help Fred,
Roger