If no results then move to next qryDef.... (1 Viewer)

dj59

Registered User.
Local time
Today, 02:32
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:32
Joined
Aug 30, 2003
Messages
36,125
You can use a DCount() on the query and test for > 0.
 

dj59

Registered User.
Local time
Today, 02:32
Joined
Jul 27, 2012
Messages
70
Thank You!
Code:
if Dcount("*","qry_175") > 0 then
Did it....
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:32
Joined
Aug 30, 2003
Messages
36,125
Happy to help!
 

Users who are viewing this thread

Top Bottom