Results 1 to 3 of 3
  1. #1
    dj59 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    13

    If no records returned, go to next QueryDef.....

    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
    
                  'If no results then go to Set qdf = CurrentDb.QueryDefs("qry_175")
                  'Else go to next line and output rpt.
    
                     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

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    if Dcount("*","qry_175") > 0 then

  3. #3
    dj59 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    13
    Thank You! solved!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-26-2013, 01:41 AM
  2. Replies: 5
    Last Post: 04-19-2012, 10:13 AM
  3. Replies: 2
    Last Post: 05-26-2011, 12:15 PM
  4. Replies: 1
    Last Post: 04-12-2011, 05:19 PM
  5. Counting returned records in a query
    By johncob in forum Queries
    Replies: 0
    Last Post: 02-11-2009, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums