Hi
Newbie here. I keep getting the 2501 error and cannot seem to find the error. When a click the button the report I need does open. I am not sure whether the fact I have a subreport built into the main report affects the below code or does the subreport also have to be in the code
Please could someone have a look at my code to see where the problem is:
Private Sub BCWeeklyProductionReports_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileName As String
Dim temp As String
Dim mypath As String
mypath = "C:\Users\Richard\Desktop\1Life Broker Services\Automatic Reports\BC Weekly Production\Weekly Stats Per Region Per BC - "
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT distinct [Region] FROM [bc statistics vS Targets]", dbOpenSnapshot)
Do While Not rs.EOF
temp = rs("region")
MyFileName = rs("region") & ".PDF"
DoCmd.OpenReport "Regional Production Stats", acViewReport, , "[region]='" & temp & "'"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
DoCmd.Close acReport, "Regional Production Stats Order By region"
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Thanks in advance
Richard
Newbie here. I keep getting the 2501 error and cannot seem to find the error. When a click the button the report I need does open. I am not sure whether the fact I have a subreport built into the main report affects the below code or does the subreport also have to be in the code
Please could someone have a look at my code to see where the problem is:
Private Sub BCWeeklyProductionReports_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileName As String
Dim temp As String
Dim mypath As String
mypath = "C:\Users\Richard\Desktop\1Life Broker Services\Automatic Reports\BC Weekly Production\Weekly Stats Per Region Per BC - "
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT distinct [Region] FROM [bc statistics vS Targets]", dbOpenSnapshot)
Do While Not rs.EOF
temp = rs("region")
MyFileName = rs("region") & ".PDF"
DoCmd.OpenReport "Regional Production Stats", acViewReport, , "[region]='" & temp & "'"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
DoCmd.Close acReport, "Regional Production Stats Order By region"
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Thanks in advance
Richard