I'm struggling with the same issue. The criteria will not pass to the report. I have Access 2000 but not QueryDef so may be that a library is off. I've read every FAQ I can find but none offer a solution. I can't use a Query because my selection criteria are complicated. The input comes from three list boxes on a form. The code is something like:
Set conADOConnection = CurrentProject.Connection
conADO.ConnectionString = CurrentProject.BaseConnectionString
'first part of strSQL true in all events
strSQL = "SELECT rep_company, discl_topic, discl_name," & _
"discl_period, discl_para, disclosure, [etc] FROM " & _
"aud_ltr_dat WHERE discl_cls_opn <> 'C'"
' now get portion of SQL statement relating to period
Select Case strPeriod
Case ""
' nothing to do here - pulling all periods
Case Else
strSQL = strSQL & " AND (discl_period = '" & _
strPeriod & "' OR discl_period = '2000All')"
End Select
' now get portion of SQL statement relating to topic
Select Case strTopic
Case "All"
strSQL = strSQL & " AND Mid(discl_topic, 2, 7) <> 'Boilerp'"
Case Else
strSQL = strSQL & " AND discl_topic = '" & strTopic & "'"
End Select
' now get portion of SQL statement relating to company
Select Case strCompany
Case "zAll"
strSQL = strSQL & _
" ORDER BY rep_company, discl_topic, [etc]"
Case "Subs"
strSQL = strSQL & " AND rep_company <> 'ACME'" & _
" ORDER BY rep_company, discl_topic, [etc]"
Case Else
If strCompany = "ACME" Then
strSQL = strSQL & " AND (rep_company = '" & strCompany & _
"' OR rep_company = 'zAll')" & _
" ORDER BY rep_company, discl_topic, [etc]"
Else
strSQL = strSQL & " AND (rep_company = '" & strCompany & _
"' OR rep_company = 'zAll' OR rep_company = 'Subs')" & _
" ORDER BY rep_company, discl_topic, [etc]"
End If
End Select
Dim objRSetRpt As New ADODB.Recordset
objRSetRpt.Open strSQL, CurrentProject.Connection, _
adOpenStatic, adLockOptimistic
I know the SQL statement works because I can force my way through with a series of MsgBoxes. But the report result is all the records print if the main table is the source or no records print if the main table is not the source. Can a code-built recordset be the source for a report? IF so, how? Much appreciated.
Greg Gol
greg.golazeski@exeloncorp.com