If no results then move to next qryDef....

dj59

Registered User.
Local time
, 19:06
Joined
Jul 27, 2012
Messages
70
I can't seem to figure out how to write this IF statement.
Any help is appreciated: See my commented out lines in the following code.

Code:
....
    'open your query as RecordSource
    Set qdf = CurrentDb.QueryDefs("qry_55")
        With qdf
            qdfOLD = .SQL
            .SQL = Replace(.SQL, "c.cnty_cd ='01'", "c.cnty_cd =" & "'" & x & "'")
                DoCmd.OpenQuery "qry_55"
                DoCmd.Close
 
[COLOR=red]              'If no results then go to Set qdf = CurrentDb.QueryDefs("qry_175")[/COLOR]
[COLOR=red]              'Else go to next line and output rpt.[/COLOR]
 
                 DoCmd.OutputTo acOutputReport, "Rpt_55", acFormatPDF, _
                    "C:\Test\" & x & "\SS" & x & "Rpt55.pdf", False
             .SQL = qdfOLD ' Reset SQL to old setting
        End With '55
 
    Set qdf = CurrentDb.QueryDefs("qry_175")
        With qdf
            qdfOLD = .SQL
            .SQL = Replace(.SQL, "(cp.cnty_cd)= '01'", "(cp.cnty_cd)= " & "'" & x & "'")
                DoCmd.OpenQuery "qry_175"
                DoCmd.Close
               'export report 175
                DoCmd.OutputTo acOutputReport, "Rpt_175", acFormatPDF, _
                    "C:\Test\" & x & "\SS" & x & "Rpt175.pdf", False
             .SQL = qdfOLD ' Reset SQL to old setting
        End With '175
 
You can use a DCount() on the query and test for > 0.
 
Thank You!
Code:
if Dcount("*","qry_175") > 0 then
Did it....
 

Users who are viewing this thread

Back
Top Bottom