Full Version: Where Clauses not combining
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
pbrown2
Can someone help.....

Strwhere = strwhere & strwheret

DoCmd.OpenReport "rptSummary", acViewPreview, , strwhere

However the debugger appears and it seems the "&" between strwhere & strwheret is not performing the combining. Basically strwhere = result of option group and strwheret= option of another group so the two results need to combined to make the final where claus.
Jack Cowley
Are you trying to add numbers or concatenate strings? If you are adding numbers try:

Dim Answer As Integer
Dim strWhere As Integer
Dim strWhere1 As Integer

Answer = strWhere + strWhere1

If you are concatenating strings be sure you dimension your variables as strings...

hth,
Jack
pbrown2
That works great for joining the where statements however I think something else may be up... no matter which check I use ADMINCK / TRIMCK / CHASSISCK all three show up. They are not set as a option group because it may be needed to pull a combination of the three. Here is the complete code:


Private Sub RunReport_Click()
Dim Answer As String
Dim strwhere As String
Dim strwheret As String

Dim isgm As String
If Me.Plant = 0 Then
MsgBox "No plant selected"
Exit Sub
Else
Select Case Me.Plant
Case 1
strwhere = "[Plant] = 'Altima T&C'"
Case 2
strwhere = "[Plant] = 'Base T&C'"
Case 3
strwhere = "[Plant]= 'Altima T&C' or 'Base T&C'"
Case 4
'different report will run -- to be added at a later date
End Select
If Me.AdminCk = True And Me.TrimCk = False And Me.ChassisCk = False Then
strwheret = "[Area] = 'Admin'"
Else
If Me.AdminCk = True And Me.TrimCk = True And Me.ChassisCk = False Then
strwheret = "[Area]= 'Admin' Or 'Trim'"
Else
If Me.AdminCk = True And Me.TrimCk = False And Me.ChassisCk = True Then
strwheret = "[Area]= 'Admin' or 'Chassis'"
Else
If Me.AdminCk = False And Me.TrimCk = False And Me.ChassisCk = True Then
strwheret = "[Area]= 'Chassis'"
Else
If Me.AdminCk = False And Me.TrimCk = True And Me.ChassisCk = True Then
strwheret = "[Area]= 'Chassis' Or 'Trim'"
Else
If Me.AdminCk = False And Me.TrimCk = True And Me.ChassisCk = False Then
strwheret = "[Area]= 'Trim'"
End If
End If
End If
End If
End If
End If
Answer = strwhere + strwheret

' If DCount("*", "qrySummary", strwhere) = 0 Then
'MsgBox "There are no items to display for this selection set", vbInformation
'Else
DoCmd.OpenReport "rptSummary", acViewPreview, , Answer
'End If
'WhereCondition = strWhere
Exit Sub
End If

End Sub
Jack Cowley
Try:

If Me.AdminCk = True And Me.TrimCk = False And Me.ChassisCk = False Then
strwheret = "[Area] = 'Admin'"
ElseIf Me.AdminCk = True And Me.TrimCk = True And Me.ChassisCk = False Then
strwheret = "[Area]= 'Admin' Or 'Trim'"
ElseIf Me.AdminCk = True And Me.TrimCk = False And Me.ChassisCk = True Then
strwheret = "[Area]= 'Admin' or 'Chassis'"
ElseIf Me.AdminCk = False And Me.TrimCk = False And Me.ChassisCk = True Then
strwheret = "[Area]= 'Chassis'"
ElseIf Me.AdminCk = False And Me.TrimCk = True And Me.ChassisCk = True Then
strwheret = "[Area]= 'Chassis' Or 'Trim'"
ElseIf Me.AdminCk = False And Me.TrimCk = True And Me.ChassisCk = False Then
strwheret = "[Area]= 'Trim'"
End If

If you still see all 3 then put stop above this code and step through it and see why you are not getting the answer you expect.

hth,
Jack
pbrown2
When Base T&C (option 2) from the first section and me.trimck is checked the "elseif..." code produces the following error

Syntax error (missing operator) in query expression'([Plant]='Base T&C'[Area='Trim')'

It appears that the + or & is not working for some reason between strwhere and strwheret

Any ideas?
Jack Cowley
Here is a sample of the syntax for strwhere:

strwhere = "([Plant]= 'Altima T&C' Or [Plant] = 'Base T&C')"

and strwheret:

strwheret = "([Area]= 'Admin' Or [Area] = 'Trim')"

And your concatenation:

Answer = strwhere & " And " & strwheret

I cannot test this code, but it should work. Change all where clauses where you have an Or in the syntax.

hth,
Jack
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.