With the attached function, i'm trying to create a report that shows the same recordset that is extracted using the "Set Cusrs = dbs.OpenRecordset(CusQry, dbOpenSnapshot)" statement which works fine. It gives me exactly the records that i want. Yet when it does the "DoCmd.OpenReport" statement it only gives me a blank report. No errors. Why ?
The "sa_hdr.post_dat" table field is defined as TEXT formatted YYYYMMDD.
Any help greatly appreciated.
Thanks,
Tony
===========================================================
Function CustQuery()
On Error GoTo CustQueryError
CustQuery = 1
RptQry = "(sa_lin.item_no >= '" & [Forms]![Form1]![StrItm] & "' " & _
"OR " & [Forms]![Form1]![StrItmChk] & " = True) " & _
"AND (sa_lin.item_no <= '" & [Forms]![Form1]![EndItm] & "' "
& _
"OR " & [Forms]![Form1]![EndItmChk] & " = True) " & _
"AND (sa_hdr.post_dat >= '" &
Format([Forms]![Form1]![StrDat], "yyyymmdd"
& "' " & _
"OR " & [Forms]![Form1]![StrDatChk] & " = True) " & _
"AND (sa_hdr.post_dat <= '" &
Format([Forms]![Form1]![EndDat], "yyyymmdd"
& "' " & _
"OR " & [Forms]![Form1]![EndDatChk] & " = True) " & _
"AND (cust.zip_cod >= '" & [Forms]![Form1]![StrZip] & "' " &
_
"OR " & [Forms]![Form1]![StrZipChk] & " = True) " & _
"AND (cust.zip_cod <= '" & [Forms]![Form1]![EndZip] & "' " &
_
"OR " & [Forms]![Form1]![EndZipChk] & " = True) " & _
"AND (cust.bal >= " & [Forms]![Form1]![StrSalAmt] & " " & _
"OR " & [Forms]![Form1]![StrSalAmtChk] & " = True) " & _
"AND (cust.bal <= " & [Forms]![Form1]![EndSalAmt] & " " & _
"OR " & [Forms]![Form1]![EndSalAmtChk] & " = True) " & _
"AND (cust.cat = '" & [Forms]![Form1]![CusCat] & "' " & _
"OR " & [Forms]![Form1]![CusCatChk] & " = True) " & _
"AND ((" & [Forms]![Form1]![ExcCustChk] & " = false) " & _
"or (" & [Forms]![Form1]![ExcCustChk] & " = true and
cust.email_adrs > ' ')) "
CusQry = "SELECT cust.nam, " & _
"cust.adrs_1, " & _
"cust.adrs_2, " & _
"cust.city, " & _
"cust.state, " & _
"cust.zip_cod, " & _
"cust.email_adrs, " & _
"cust.phone_no_1, " & _
"sa_lin.item_no AS itemnumber, " & _
"MAX(sa_hdr.post_dat) AS postdate " & _
"FROM (cust " & _
"INNER JOIN sa_hdr " & _
"ON cust.nbr = sa_hdr.cust_no) " & _
"INNER JOIN sa_lin " & _
"ON sa_hdr.ticket_no = sa_lin.hdr_ticket_no " & _
"WHERE " & RptQry & "GROUP BY cust.nam, " & _
"cust.adrs_1, " & _
"cust.adrs_2, " & _
"cust.city, " & _
"cust.state, " & _
"cust.zip_cod, " & _
"cust.email_adrs, " & _
"cust.phone_no_1, " & _
"sa_lin.item_no " & _
"ORDER BY cust.nam;"
Debug.Print RptQry
Set Cusrs = dbs.OpenRecordset(CusQry, dbOpenSnapshot)
If (Cusrs.RecordCount = 0) Then
CustQuery = 0
Else
If [Forms]![Form1]![Frame39] <> 2 Then
Debug.Print RptQry
DoCmd.OpenReport "cust3", acPreview, , RptQry
End If
End If
Exit Function
CustQueryError:
MsgBox "Error " & Err.Number & " (" & Err.Description & "
", vbCritical
CustQuery = 0
End Function
The "sa_hdr.post_dat" table field is defined as TEXT formatted YYYYMMDD.
Any help greatly appreciated.
Thanks,
Tony
===========================================================
Function CustQuery()
On Error GoTo CustQueryError
CustQuery = 1
RptQry = "(sa_lin.item_no >= '" & [Forms]![Form1]![StrItm] & "' " & _
"OR " & [Forms]![Form1]![StrItmChk] & " = True) " & _
"AND (sa_lin.item_no <= '" & [Forms]![Form1]![EndItm] & "' "
& _
"OR " & [Forms]![Form1]![EndItmChk] & " = True) " & _
"AND (sa_hdr.post_dat >= '" &
Format([Forms]![Form1]![StrDat], "yyyymmdd"
"OR " & [Forms]![Form1]![StrDatChk] & " = True) " & _
"AND (sa_hdr.post_dat <= '" &
Format([Forms]![Form1]![EndDat], "yyyymmdd"
"OR " & [Forms]![Form1]![EndDatChk] & " = True) " & _
"AND (cust.zip_cod >= '" & [Forms]![Form1]![StrZip] & "' " &
_
"OR " & [Forms]![Form1]![StrZipChk] & " = True) " & _
"AND (cust.zip_cod <= '" & [Forms]![Form1]![EndZip] & "' " &
_
"OR " & [Forms]![Form1]![EndZipChk] & " = True) " & _
"AND (cust.bal >= " & [Forms]![Form1]![StrSalAmt] & " " & _
"OR " & [Forms]![Form1]![StrSalAmtChk] & " = True) " & _
"AND (cust.bal <= " & [Forms]![Form1]![EndSalAmt] & " " & _
"OR " & [Forms]![Form1]![EndSalAmtChk] & " = True) " & _
"AND (cust.cat = '" & [Forms]![Form1]![CusCat] & "' " & _
"OR " & [Forms]![Form1]![CusCatChk] & " = True) " & _
"AND ((" & [Forms]![Form1]![ExcCustChk] & " = false) " & _
"or (" & [Forms]![Form1]![ExcCustChk] & " = true and
cust.email_adrs > ' ')) "
CusQry = "SELECT cust.nam, " & _
"cust.adrs_1, " & _
"cust.adrs_2, " & _
"cust.city, " & _
"cust.state, " & _
"cust.zip_cod, " & _
"cust.email_adrs, " & _
"cust.phone_no_1, " & _
"sa_lin.item_no AS itemnumber, " & _
"MAX(sa_hdr.post_dat) AS postdate " & _
"FROM (cust " & _
"INNER JOIN sa_hdr " & _
"ON cust.nbr = sa_hdr.cust_no) " & _
"INNER JOIN sa_lin " & _
"ON sa_hdr.ticket_no = sa_lin.hdr_ticket_no " & _
"WHERE " & RptQry & "GROUP BY cust.nam, " & _
"cust.adrs_1, " & _
"cust.adrs_2, " & _
"cust.city, " & _
"cust.state, " & _
"cust.zip_cod, " & _
"cust.email_adrs, " & _
"cust.phone_no_1, " & _
"sa_lin.item_no " & _
"ORDER BY cust.nam;"
Debug.Print RptQry
Set Cusrs = dbs.OpenRecordset(CusQry, dbOpenSnapshot)
If (Cusrs.RecordCount = 0) Then
CustQuery = 0
Else
If [Forms]![Form1]![Frame39] <> 2 Then
Debug.Print RptQry
DoCmd.OpenReport "cust3", acPreview, , RptQry
End If
End If
Exit Function
CustQueryError:
MsgBox "Error " & Err.Number & " (" & Err.Description & "
CustQuery = 0
End Function