I get a run time error '13' message for the following line:type mismatch
Set rstAgency = dbs.OpenRecordset("Table1")
Why am I getting this message.
This is the coding I generated:
Option Compare Database
Public Sub PrintAgencyReport()
Dim dbs, Database
Dim tdf, TableDef
Dim rstAgency As Recordset
Dim strWhere As String
Dim strReportName As String
Dim strFileName As String
Dim rstTestForRecords As Recordset
Dim strWhereTest As String
' Return reference to current database
Set dbs = CurrentDb
' Return reference to Agency table
Set tdf = dbs.TableDefs!Table1
' Open the AgencyList table containing agencies
Set rstAgency = dbs.OpenRecordset("Table1")
' Loop through AgencyList table to get the agency _
parameter for the report and path to send report
With rstAgency
.MoveFirst
Do Until .EOF
strReportName = "Report1"
strWhere = "[Agency]='" & ![Agency] & "'"
strFileName = "c:\FDLEfiles" & ![Agency] & "Report1.html"
strWhereTest = "Select * From qryReport1 Where" & strWhere
Set rstTestForRecords = dbs.OpenRecordset(strWhereTest)
If rstTestForRecords.BOF And rstTestForRecords.EOF Then
Else
DoCmd.OpenReport strReportName, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, strReportName, "HTML(*.html)", strFileName
DoCmd.Close
End If
.MoveNext
Loop
.Close
End With
End Sub
Set rstAgency = dbs.OpenRecordset("Table1")
Why am I getting this message.
This is the coding I generated:
Option Compare Database
Public Sub PrintAgencyReport()
Dim dbs, Database
Dim tdf, TableDef
Dim rstAgency As Recordset
Dim strWhere As String
Dim strReportName As String
Dim strFileName As String
Dim rstTestForRecords As Recordset
Dim strWhereTest As String
' Return reference to current database
Set dbs = CurrentDb
' Return reference to Agency table
Set tdf = dbs.TableDefs!Table1
' Open the AgencyList table containing agencies
Set rstAgency = dbs.OpenRecordset("Table1")
' Loop through AgencyList table to get the agency _
parameter for the report and path to send report
With rstAgency
.MoveFirst
Do Until .EOF
strReportName = "Report1"
strWhere = "[Agency]='" & ![Agency] & "'"
strFileName = "c:\FDLEfiles" & ![Agency] & "Report1.html"
strWhereTest = "Select * From qryReport1 Where" & strWhere
Set rstTestForRecords = dbs.OpenRecordset(strWhereTest)
If rstTestForRecords.BOF And rstTestForRecords.EOF Then
Else
DoCmd.OpenReport strReportName, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, strReportName, "HTML(*.html)", strFileName
DoCmd.Close
End If
.MoveNext
Loop
.Close
End With
End Sub