D
Douglas J. Steele
Right after your code
If Len(strWhere) > 6 Then
strWhere = Left$(strWhere, Len(strWhere) - 5)
End If
put the statement
Debug.Print strWhere
Once the code runs, go to the Immediate Window (Ctrl-G) and see what's
written there.
It's possible your combo boxes aren't bound to the field to which you think
they're bound.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Hi Doug -
Sorry, I was responding in the middle of the conversation that
everyone was having, I did not see the new code.
OK, the report now opens correctly if I have no combo box selections.
If I select something in the combo boxes for SBT Account (text
format), ADM (text format), or Month (number format) I receive a Run-
time error 3075: Syntax error (missing operator) in query expression
'[ARCHIVE_ADM_Summary].ADM = 'AE' (error is the same for SBT account
selection, just replace 'AE' with 'Meijer')
Or I get a Run-time error 3075: Syntax error (missing operator) in
query expression '[ARCHIVE_ADM_Summary].[Month] = '.
If I select something in the Region combo box I get an 'Enter
Parameter Value' box that opens up.
If I select something in the Year combo box (right now only 2009 is
populated in my tables) I get a blank report, no error messages.
Here is the updated code that I have right now, I believe that I
captured the most recent recommendations:
Dim strWhere As String
Dim strReportName As String
strWhere = ""
If Not IsNull([Forms]![Main_Form]![ADM Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].ADM = '"
strWhere = strWhere & [Forms]![Main_Form]![ADM Select] & "' AND"
End If
If Not IsNull([Forms]![Main_Form]![Region Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].Region = "
strWhere = strWhere & [Forms]![Main_Form]![Region Select] & "'
AND"
End If
If Not IsNull([Forms]![Main_Form]![SBT Account Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[SBT Account] = '"
strWhere = strWhere & [Forms]![Main_Form]![SBT Account Select] &
"' And"
End If
If Not IsNull([Forms]![Main_Form]![Month Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[Month] = "
strWhere = strWhere & [Forms]![Main_Form]![Month Select] & "
And"
End If
If Not IsNull([Forms]![Main_Form]![Year Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[Year] = "
strWhere = strWhere & [Forms]![Main_Form]![Year Select] & " And"
End If
If Len(strWhere) > 6 Then
strWhere = Left$(strWhere, Len(strWhere) - 5)
End If
DoCmd.OpenReport "ADM_Test_2", acViewPreview, , strWhere
If Len(strWhere) > 6 Then
strWhere = Left$(strWhere, Len(strWhere) - 5)
End If
put the statement
Debug.Print strWhere
Once the code runs, go to the Immediate Window (Ctrl-G) and see what's
written there.
It's possible your combo boxes aren't bound to the field to which you think
they're bound.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Hi Doug -
Sorry, I was responding in the middle of the conversation that
everyone was having, I did not see the new code.
OK, the report now opens correctly if I have no combo box selections.
If I select something in the combo boxes for SBT Account (text
format), ADM (text format), or Month (number format) I receive a Run-
time error 3075: Syntax error (missing operator) in query expression
'[ARCHIVE_ADM_Summary].ADM = 'AE' (error is the same for SBT account
selection, just replace 'AE' with 'Meijer')
Or I get a Run-time error 3075: Syntax error (missing operator) in
query expression '[ARCHIVE_ADM_Summary].[Month] = '.
If I select something in the Region combo box I get an 'Enter
Parameter Value' box that opens up.
If I select something in the Year combo box (right now only 2009 is
populated in my tables) I get a blank report, no error messages.
Here is the updated code that I have right now, I believe that I
captured the most recent recommendations:
Dim strWhere As String
Dim strReportName As String
strWhere = ""
If Not IsNull([Forms]![Main_Form]![ADM Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].ADM = '"
strWhere = strWhere & [Forms]![Main_Form]![ADM Select] & "' AND"
End If
If Not IsNull([Forms]![Main_Form]![Region Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].Region = "
strWhere = strWhere & [Forms]![Main_Form]![Region Select] & "'
AND"
End If
If Not IsNull([Forms]![Main_Form]![SBT Account Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[SBT Account] = '"
strWhere = strWhere & [Forms]![Main_Form]![SBT Account Select] &
"' And"
End If
If Not IsNull([Forms]![Main_Form]![Month Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[Month] = "
strWhere = strWhere & [Forms]![Main_Form]![Month Select] & "
And"
End If
If Not IsNull([Forms]![Main_Form]![Year Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[Year] = "
strWhere = strWhere & [Forms]![Main_Form]![Year Select] & " And"
End If
If Len(strWhere) > 6 Then
strWhere = Left$(strWhere, Len(strWhere) - 5)
End If
DoCmd.OpenReport "ADM_Test_2", acViewPreview, , strWhere
What's the actual code you're using (Steve's code does not have WHERE 1 =
1
anywhere in it).
Incidentally, Steve's code does have an error. You should be adding "' AND
", not "' AND" (the difference is the space after the word AND)
and the line of code
strWhere = Left$(strWhere, Len(strWhere) - 4)
should be
strWhere = Left$(strWhere, Len(strWhere) - 5)
--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)
OK, made the changes. It runs for 2 seconds and then pops up with an
error 3075: Syntax error (missing operator) in query expression 'WHERE
1 = 1 AND'.
The debugger highlights the DoCmd line:
DoCmd.OpenReport "ADM_Test_2", acViewPreview, , strWhere
Is it possibly an error caused by how I built the report?
Many thanks John..... I knew that. <headsmack>
I've been creating too many recordsets in code lately...
Now the code should look like:'-------------------------------------
Dim strWhere As String
' Dim strReportName As String ' REM'ed - not usedstrWhere = ""
If Not IsNull([Forms]![Main_Form]![ADM Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].ADM = '"
strWhere = strWhere & [Forms]![Main_Form]![ADM Select] & "' AND"
End If
If Not IsNull([Forms]![Main_Form]![Region Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].Region = "
strWhere = strWhere & [Forms]![Main_Form]![Region Select] & "' AND"
End If
If Not IsNull([Forms]![Main_Form]![SBT Account Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[SBT Account] = '"
strWhere = strWhere & [Forms]![Main_Form]![SBT Account Select] & "' And"
End If
If Not IsNull([Forms]![Main_Form]![Month Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[Month] = "
strWhere = strWhere & [Forms]![Main_Form]![Month Select] & " And"
End If
If Not IsNull([Forms]![Main_Form]![Year Select]) Then
strWhere = strWhere & " [ARCHIVE_ADM_Summary].[Year] = "
strWhere = strWhere & [Forms]![Main_Form]![Year Select] & " And"
End If'remove the last 4 chars
If Len(strWhere) > 6 Then
strWhere = Left$(strWhere, Len(strWhere) - 4)
End IfDoCmd.OpenReport "ADM_Test_2", acViewPreview, , strWhere
'-------------------------------------- Show quoted text -- Hide quoted text -
- Show quoted text -