I have this code that creates a report combining two separate queries into an excel template with two sheets, this runs perfect, until say no records are in the first query, throughs out an error.. how to i tell it to continue onto the next pls?
Dim rst1
Dim vFile1
vFile1 = "Template_Location.xlsx"
Set rst1 = CurrentDb.OpenRecordset("Data_1")
rst1.MoveLast
With XL
.Visible = False
.Workbooks.Open vFile1
.Sheets("New").Select
.Range("A2").Select
.ActiveCell.CopyFromRecordset rst1
.ActiveWorkbook.SaveAs filename:=("C:\Local-Saved_Location.xlsx")
.ActiveWorkbook.Close
Dim rst2
Dim vFile2
vFile2 = "C:\Local-Saved_Location.xlsx"
Set rst2 = CurrentDb.OpenRecordset("Data_2")
rst2.MoveLast
With XL
.Visible = False
.Workbooks.Open vFile2
.Sheets("Update").Select
.Range("A2").Select
.ActiveCell.CopyFromRecordset rst2
.ActiveWorkbook.SaveAs filename:=("C:\Report Location.xlsx")
.ActiveWorkbook.Close
.Application.Quit
Dim rst1
Dim vFile1
vFile1 = "Template_Location.xlsx"
Set rst1 = CurrentDb.OpenRecordset("Data_1")
rst1.MoveLast
With XL
.Visible = False
.Workbooks.Open vFile1
.Sheets("New").Select
.Range("A2").Select
.ActiveCell.CopyFromRecordset rst1
.ActiveWorkbook.SaveAs filename:=("C:\Local-Saved_Location.xlsx")
.ActiveWorkbook.Close
Dim rst2
Dim vFile2
vFile2 = "C:\Local-Saved_Location.xlsx"
Set rst2 = CurrentDb.OpenRecordset("Data_2")
rst2.MoveLast
With XL
.Visible = False
.Workbooks.Open vFile2
.Sheets("Update").Select
.Range("A2").Select
.ActiveCell.CopyFromRecordset rst2
.ActiveWorkbook.SaveAs filename:=("C:\Report Location.xlsx")
.ActiveWorkbook.Close
.Application.Quit