Question on Allen Browne Query form....

G

Guest

Here is a snippet of my code (which anyone familiar with the form will be
able to recognize). Where I'm having problems is starting at the [chkQS]
portion of the code. With this line missing, it works fine:

If Not IsNull(Me.cboPIN) Then
strWHERE = strWHERE & "([PIN] = """ & Me.cboPIN & """) AND "
End If

If Me.[chkQS] = "Yes" Then
strWHERE = strWHERE & "([RDisposition] = ""New Tool Required"" OR
[RDisposition] = ""Opp-New Tool"" OR [RDisposition] = ""Rework"" OR
[RDisposition] = ""Opp-Rework"") AND "
End If

lngLen = Len(strWHERE) - 5

If lngLen <= 0 Then
MsgBox "No criteria selected", vbInformation, "No Search Criteria"
Else
strWHERE = Left$(strWHERE, lngLen)
Debug.Print strWHERE
Me.Filter = strWHERE
Me.FilterOn = True
End If

End Sub

I also tried a permutation:

If Not IsNull(Me.chkQS) Then
strWHERE = strWHERE & "([RDisposition] = ""New Tool Required"" OR
[RDisposition] = ""Opp-New Tool"" OR [RDisposition] = ""Rework"" OR
[RDisposition] = ""Opp-Rework"") AND "

This worked, except the code always ran that portion of the query. Being a
non-programmer, I'm not sure why the code isn't working the way I want it to.
Could someone please help me with my code syntax for this checkbox? Thank
you!
 
O

OldPro

Here is a snippet of my code (which anyone familiar with the form will be
able to recognize). Where I'm having problems is starting at the [chkQS]
portion of the code. With this line missing, it works fine:

If Not IsNull(Me.cboPIN) Then
strWHERE = strWHERE & "([PIN] = """ & Me.cboPIN & """) AND "
End If

If Me.[chkQS] = "Yes" Then
strWHERE = strWHERE & "([RDisposition] = ""New Tool Required"" OR
[RDisposition] = ""Opp-New Tool"" OR [RDisposition] = ""Rework"" OR
[RDisposition] = ""Opp-Rework"") AND "
End If

lngLen = Len(strWHERE) - 5

If lngLen <= 0 Then
MsgBox "No criteria selected", vbInformation, "No Search Criteria"
Else
strWHERE = Left$(strWHERE, lngLen)
Debug.Print strWHERE
Me.Filter = strWHERE
Me.FilterOn = True
End If

End Sub

I also tried a permutation:

If Not IsNull(Me.chkQS) Then
strWHERE = strWHERE & "([RDisposition] = ""New Tool Required"" OR
[RDisposition] = ""Opp-New Tool"" OR [RDisposition] = ""Rework"" OR
[RDisposition] = ""Opp-Rework"") AND "

This worked, except the code always ran that portion of the query. Being a
non-programmer, I'm not sure why the code isn't working the way I want it to.
Could someone please help me with my code syntax for this checkbox? Thank
you!

Is the code properly named to match your environment? In other words,
is there a field called "RDisposition" and a chkbox call chkQS, etc.?
The double quotes seem odd... did you copy the code or type it in
yourself? Usually text is delimited with singles quotes in a SQL
query. Are there any input boxes on the form? I don't see where this
code (other than the checkbox) refers to any controls on the form...
It probably won't work correctly until you understand what each
portion is supposed to do, and thus you will be able to correct it.
Do you have a grasp of what the purpose of each line is? Can you tell
us what this code is supposed to do?
 
G

Guest

The code comes from the form provided by AB at this link:
http://allenbrowne.com/ser-62.html

Allow me to once again state that EVERYTHING else works fine, except for the
checkbox (chkQS) boolean portion of the code. When it is removed, the code
executes flawlessly. With the second line version I posted, the code works
exactly as planned, except that the line is "always on" and not selective
with respect to the checkbox being checked. All of my names are correct (no
typos; I idiot-checked that before posting). This is definitely something
specific to the syntax of the boolean portion of the code.
 
G

Guest

Try:
If Me.[chkQS] = -1 Then...
or If Me.[chkQS] = true Then...
or If Me.[chkQS] Then...

"If Not IsNull(Me.chkQS) Then" portion of code would always run because
me.chkQS's value would not be null since a checkbox is either true or false, .

HTH
 
G

Guest

TOUCHDOWN~!

If Me.[chkQS] = True Then...

was the one that worked. Thank you again!


mtn244 said:
Try:
If Me.[chkQS] = -1 Then...
or If Me.[chkQS] = true Then...
or If Me.[chkQS] Then...

"If Not IsNull(Me.chkQS) Then" portion of code would always run because
me.chkQS's value would not be null since a checkbox is either true or false, .

HTH

J. Keggerlord said:
Here is a snippet of my code (which anyone familiar with the form will be
able to recognize). Where I'm having problems is starting at the [chkQS]
portion of the code. With this line missing, it works fine:

If Not IsNull(Me.cboPIN) Then
strWHERE = strWHERE & "([PIN] = """ & Me.cboPIN & """) AND "
End If

If Me.[chkQS] = "Yes" Then
strWHERE = strWHERE & "([RDisposition] = ""New Tool Required"" OR
[RDisposition] = ""Opp-New Tool"" OR [RDisposition] = ""Rework"" OR
[RDisposition] = ""Opp-Rework"") AND "
End If

lngLen = Len(strWHERE) - 5

If lngLen <= 0 Then
MsgBox "No criteria selected", vbInformation, "No Search Criteria"
Else
strWHERE = Left$(strWHERE, lngLen)
Debug.Print strWHERE
Me.Filter = strWHERE
Me.FilterOn = True
End If

End Sub

I also tried a permutation:

If Not IsNull(Me.chkQS) Then
strWHERE = strWHERE & "([RDisposition] = ""New Tool Required"" OR
[RDisposition] = ""Opp-New Tool"" OR [RDisposition] = ""Rework"" OR
[RDisposition] = ""Opp-Rework"") AND "

This worked, except the code always ran that portion of the query. Being a
non-programmer, I'm not sure why the code isn't working the way I want it to.
Could someone please help me with my code syntax for this checkbox? Thank
you!
 

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