Hello, my first post, please can somebody help me with the following problem ?
I am writing a program which will allow me to export data from multiple queries into excel,( by calling the fields from each DAO recordset rather than transferspreadsheet method ). However, everytime I reach the 6th recordset to open and obtain data, the code fails....
Error message : Runtime error 3061
Too Few Parameters. Expected 1.
and it breaks on the following line of code :
Set Rst6 = Dbs.OpenRecordset("QrySalesbyChannelDlr")
Is there a limit to the number of recordsets you can access in a query
Any help greatly appreciated as deadline for this program passed
'Territory report generator
Dim Dbs As DAO.Database
Dim ObjXL As Excel.Application
Dim ObjWkb As Excel.Workbook
Dim ObjSht As Excel.Worksheet
Dim Rst1, Rst2, Rst3, Rst4, Rst5 As DAO.Recordset
Dim Rst6, Rst7, Rst8, Rst9, Rst10 As DAO.Recordset
Dim Dir, File, FullDir As String
Dim IntC1 As Integer
Dir = "W:\Maz Urban Science\Development"
File = "SchoolReportTemplate.xls"
FullDir = Dir & "\" & File
DoCmd.OpenQuery "QrySelectTerritory"
Set Dbs = CurrentDb
Set Rst1 = Dbs.OpenRecordset("TblSelectTerritory")
Select Case MsgBox("Confirm you wish to generate School Report files ?", vbYesNo, "School Report Files")
Case vbYes
DoCmd.Hourglass True
Rst1.MoveFirst
Do Until Rst1.EOF
Me.TxtDealer = (Rst1![DealerNo])
'Run the Cross tab make table queries now !
DoCmd.OpenQuery "QrySVOCtabData", acViewNormal
DoCmd.OpenQuery "QryTerSVOCtabData", acViewNormal
DoCmd.OpenQuery "QryNatSvoCtabData", acViewNormal
DoCmd.OpenQuery "QryDlrSalesbyMthCtabData", acViewNormal
Set ObjXL = New Excel.Application
Set ObjWkb = ObjXL.Workbooks.Open(FullDir)
'========================================================
Set Rst2 = Dbs.OpenRecordset("QrySVOCtab")
Rst2.MoveFirst
Set ObjSht = ObjWkb.Worksheets("Sales")
With ObjSht
.Cells(21, 3) = (Rst2![jan])
.Cells(21, 4) = (Rst2![feb])
.Cells(21, 5) = (Rst2![mar])
.Cells(21, 6) = (Rst2![apr])
.Cells(21, 7) = (Rst2![may])
.Cells(21, 8) = (Rst2![jun])
.Cells(21, 9) = (Rst2![jul])
.Cells(21, 10) = (Rst2![aug])
.Cells(21, 11) = (Rst2![sep])
.Cells(21, 12) = (Rst2![Oct])
.Cells(21, 13) = (Rst2![nov])
.Cells(21, 14) = (Rst2![dec])
End With
Rst2.MoveNext
With ObjSht
.Cells(22, 3) = (Rst2![jan])
.Cells(22, 4) = (Rst2![feb])
.Cells(22, 5) = (Rst2![mar])
.Cells(22, 6) = (Rst2![apr])
.Cells(22, 7) = (Rst2![may])
.Cells(22, 8) = (Rst2![jun])
.Cells(22, 9) = (Rst2![jul])
.Cells(22, 10) = (Rst2![aug])
.Cells(22, 11) = (Rst2![sep])
.Cells(22, 12) = (Rst2![Oct])
.Cells(22, 13) = (Rst2![nov])
.Cells(22, 14) = (Rst2![dec])
End With
Rst2.Close
'=======================================================
Set Rst3 = Dbs.OpenRecordset("QryTerSvOCtab")
Rst3.MoveFirst
Set ObjSht = ObjWkb.Worksheets("Data")
With ObjSht
.Cells(3, 2) = (Rst3![jan])
.Cells(3, 3) = (Rst3![feb])
.Cells(3, 4) = (Rst3![mar])
.Cells(3, 5) = (Rst3![apr])
.Cells(3, 6) = (Rst3![may])
.Cells(3, 7) = (Rst3![jun])
.Cells(3, 8) = (Rst3![jul])
.Cells(3, 9) = (Rst3![aug])
.Cells(3, 10) = (Rst3![sep])
.Cells(3, 11) = (Rst3![Oct])
.Cells(3, 12) = (Rst3![nov])
.Cells(3, 13) = (Rst3![dec])
End With
Rst3.MoveNext
With ObjSht
.Cells(4, 2) = (Rst3![jan])
.Cells(4, 3) = (Rst3![feb])
.Cells(4, 4) = (Rst3![mar])
.Cells(4, 5) = (Rst3![apr])
.Cells(4, 6) = (Rst3![may])
.Cells(4, 7) = (Rst3![jun])
.Cells(4, 8) = (Rst3![jul])
.Cells(4, 9) = (Rst3![aug])
.Cells(4, 10) = (Rst3![sep])
.Cells(4, 11) = (Rst3![Oct])
.Cells(4, 12) = (Rst3![nov])
.Cells(4, 13) = (Rst3![dec])
End With
Rst3.Close
'=====================================================
Set Rst4 = Dbs.OpenRecordset("QryNatSvoCtab")
Rst4.MoveFirst
Set ObjSht = ObjWkb.Worksheets("Data")
With ObjSht
.Cells(9, 2) = (Rst4![jan])
.Cells(9, 3) = (Rst4![feb])
.Cells(9, 4) = (Rst4![mar])
.Cells(9, 5) = (Rst4![apr])
.Cells(9, 6) = (Rst4![may])
.Cells(9, 7) = (Rst4![jun])
.Cells(9, 8) = (Rst4![jul])
.Cells(9, 9) = (Rst4![aug])
.Cells(9, 10) = (Rst4![sep])
.Cells(9, 11) = (Rst4![Oct])
.Cells(9, 12) = (Rst4![nov])
.Cells(9, 13) = (Rst4![dec])
End With
Rst4.MoveNext
With ObjSht
.Cells(10, 2) = (Rst4![jan])
.Cells(10, 3) = (Rst4![feb])
.Cells(10, 4) = (Rst4![mar])
.Cells(10, 5) = (Rst4![apr])
.Cells(10, 6) = (Rst4![may])
.Cells(10, 7) = (Rst4![jun])
.Cells(10, 8) = (Rst4![jul])
.Cells(10, 9) = (Rst4![aug])
.Cells(10, 10) = (Rst4![sep])
.Cells(10, 11) = (Rst4![Oct])
.Cells(10, 12) = (Rst4![nov])
.Cells(10, 13) = (Rst4![dec])
End With
Rst4.Close
'===================================================
Set Rst5 = Dbs.OpenRecordset("QryDlrSalesbyMthCTab")
Rst5.MoveFirst
IntC1 = 10
Do Until Rst5.EOF
Set ObjSht = ObjWkb.Worksheets("Sales")
With ObjSht
.Cells(IntC1, 19) = (Rst5![Model])
.Cells(IntC1, 20) = (Rst5![jan])
.Cells(IntC1, 21) = (Rst5![feb])
.Cells(IntC1, 22) = (Rst5![mar])
.Cells(IntC1, 23) = (Rst5![apr])
.Cells(IntC1, 24) = (Rst5![may])
.Cells(IntC1, 25) = (Rst5![jun])
.Cells(IntC1, 26) = (Rst5![jul])
.Cells(IntC1, 27) = (Rst5![aug])
.Cells(IntC1, 28) = (Rst5![sep])
'.Cells(IntC1, 29) = (Rst5![Oct])
'.Cells(IntC1, 30) = (Rst5![nov])
'.Cells(IntC1, 31) = (Rst5![dec])
End With
IntC1 = IntC1 + 1
Rst5.MoveNext
Loop
Rst5.Close
'=====================================================
Set Rst6 = Dbs.OpenRecordset("QrySalesbyChannelDlr")
Rst6.MoveFirst
IntC1 = 18
Do Until Rst6.EOF
Set ObjSht = ObjWkb.Worksheets("Data")
With ObjSht
.Cells(IntC1, 2) = (Rst5![Model])
.Cells(IntC1, 3) = (Rst5![jan])
.Cells(IntC1, 4) = (Rst5![feb])
.Cells(IntC1, 5) = (Rst5![mar])
End With
IntC1 = IntC1 + 1
Rst6.MoveNext
Loop
Rst6.Close
'=====================================================
ObjWkb.SaveAs "W:\Maz Urban Science\Development\Test\" & Rst1![DealerNo] & "PerformanceReport-" & Format(Date, "dd mmm") & ".xls"
ObjWkb.Close True
Rst1.MoveNext
Loop
Rst1.Close
Set Rst1 = Nothing
Dbs.Close
Set Dbs = Nothing
Set ObjWkb = ObjXL.Workbooks.Open(FullDir)
ObjWkb.Close
Case vbNo
End Select
MsgBox ("All actions complete")
DoCmd.Hourglass False
DoCmd.SetWarnings True
End Sub
I am writing a program which will allow me to export data from multiple queries into excel,( by calling the fields from each DAO recordset rather than transferspreadsheet method ). However, everytime I reach the 6th recordset to open and obtain data, the code fails....
Error message : Runtime error 3061
Too Few Parameters. Expected 1.
and it breaks on the following line of code :
Set Rst6 = Dbs.OpenRecordset("QrySalesbyChannelDlr")
Is there a limit to the number of recordsets you can access in a query
Any help greatly appreciated as deadline for this program passed
'Territory report generator
Dim Dbs As DAO.Database
Dim ObjXL As Excel.Application
Dim ObjWkb As Excel.Workbook
Dim ObjSht As Excel.Worksheet
Dim Rst1, Rst2, Rst3, Rst4, Rst5 As DAO.Recordset
Dim Rst6, Rst7, Rst8, Rst9, Rst10 As DAO.Recordset
Dim Dir, File, FullDir As String
Dim IntC1 As Integer
Dir = "W:\Maz Urban Science\Development"
File = "SchoolReportTemplate.xls"
FullDir = Dir & "\" & File
DoCmd.OpenQuery "QrySelectTerritory"
Set Dbs = CurrentDb
Set Rst1 = Dbs.OpenRecordset("TblSelectTerritory")
Select Case MsgBox("Confirm you wish to generate School Report files ?", vbYesNo, "School Report Files")
Case vbYes
DoCmd.Hourglass True
Rst1.MoveFirst
Do Until Rst1.EOF
Me.TxtDealer = (Rst1![DealerNo])
'Run the Cross tab make table queries now !
DoCmd.OpenQuery "QrySVOCtabData", acViewNormal
DoCmd.OpenQuery "QryTerSVOCtabData", acViewNormal
DoCmd.OpenQuery "QryNatSvoCtabData", acViewNormal
DoCmd.OpenQuery "QryDlrSalesbyMthCtabData", acViewNormal
Set ObjXL = New Excel.Application
Set ObjWkb = ObjXL.Workbooks.Open(FullDir)
'========================================================
Set Rst2 = Dbs.OpenRecordset("QrySVOCtab")
Rst2.MoveFirst
Set ObjSht = ObjWkb.Worksheets("Sales")
With ObjSht
.Cells(21, 3) = (Rst2![jan])
.Cells(21, 4) = (Rst2![feb])
.Cells(21, 5) = (Rst2![mar])
.Cells(21, 6) = (Rst2![apr])
.Cells(21, 7) = (Rst2![may])
.Cells(21, 8) = (Rst2![jun])
.Cells(21, 9) = (Rst2![jul])
.Cells(21, 10) = (Rst2![aug])
.Cells(21, 11) = (Rst2![sep])
.Cells(21, 12) = (Rst2![Oct])
.Cells(21, 13) = (Rst2![nov])
.Cells(21, 14) = (Rst2![dec])
End With
Rst2.MoveNext
With ObjSht
.Cells(22, 3) = (Rst2![jan])
.Cells(22, 4) = (Rst2![feb])
.Cells(22, 5) = (Rst2![mar])
.Cells(22, 6) = (Rst2![apr])
.Cells(22, 7) = (Rst2![may])
.Cells(22, 8) = (Rst2![jun])
.Cells(22, 9) = (Rst2![jul])
.Cells(22, 10) = (Rst2![aug])
.Cells(22, 11) = (Rst2![sep])
.Cells(22, 12) = (Rst2![Oct])
.Cells(22, 13) = (Rst2![nov])
.Cells(22, 14) = (Rst2![dec])
End With
Rst2.Close
'=======================================================
Set Rst3 = Dbs.OpenRecordset("QryTerSvOCtab")
Rst3.MoveFirst
Set ObjSht = ObjWkb.Worksheets("Data")
With ObjSht
.Cells(3, 2) = (Rst3![jan])
.Cells(3, 3) = (Rst3![feb])
.Cells(3, 4) = (Rst3![mar])
.Cells(3, 5) = (Rst3![apr])
.Cells(3, 6) = (Rst3![may])
.Cells(3, 7) = (Rst3![jun])
.Cells(3, 8) = (Rst3![jul])
.Cells(3, 9) = (Rst3![aug])
.Cells(3, 10) = (Rst3![sep])
.Cells(3, 11) = (Rst3![Oct])
.Cells(3, 12) = (Rst3![nov])
.Cells(3, 13) = (Rst3![dec])
End With
Rst3.MoveNext
With ObjSht
.Cells(4, 2) = (Rst3![jan])
.Cells(4, 3) = (Rst3![feb])
.Cells(4, 4) = (Rst3![mar])
.Cells(4, 5) = (Rst3![apr])
.Cells(4, 6) = (Rst3![may])
.Cells(4, 7) = (Rst3![jun])
.Cells(4, 8) = (Rst3![jul])
.Cells(4, 9) = (Rst3![aug])
.Cells(4, 10) = (Rst3![sep])
.Cells(4, 11) = (Rst3![Oct])
.Cells(4, 12) = (Rst3![nov])
.Cells(4, 13) = (Rst3![dec])
End With
Rst3.Close
'=====================================================
Set Rst4 = Dbs.OpenRecordset("QryNatSvoCtab")
Rst4.MoveFirst
Set ObjSht = ObjWkb.Worksheets("Data")
With ObjSht
.Cells(9, 2) = (Rst4![jan])
.Cells(9, 3) = (Rst4![feb])
.Cells(9, 4) = (Rst4![mar])
.Cells(9, 5) = (Rst4![apr])
.Cells(9, 6) = (Rst4![may])
.Cells(9, 7) = (Rst4![jun])
.Cells(9, 8) = (Rst4![jul])
.Cells(9, 9) = (Rst4![aug])
.Cells(9, 10) = (Rst4![sep])
.Cells(9, 11) = (Rst4![Oct])
.Cells(9, 12) = (Rst4![nov])
.Cells(9, 13) = (Rst4![dec])
End With
Rst4.MoveNext
With ObjSht
.Cells(10, 2) = (Rst4![jan])
.Cells(10, 3) = (Rst4![feb])
.Cells(10, 4) = (Rst4![mar])
.Cells(10, 5) = (Rst4![apr])
.Cells(10, 6) = (Rst4![may])
.Cells(10, 7) = (Rst4![jun])
.Cells(10, 8) = (Rst4![jul])
.Cells(10, 9) = (Rst4![aug])
.Cells(10, 10) = (Rst4![sep])
.Cells(10, 11) = (Rst4![Oct])
.Cells(10, 12) = (Rst4![nov])
.Cells(10, 13) = (Rst4![dec])
End With
Rst4.Close
'===================================================
Set Rst5 = Dbs.OpenRecordset("QryDlrSalesbyMthCTab")
Rst5.MoveFirst
IntC1 = 10
Do Until Rst5.EOF
Set ObjSht = ObjWkb.Worksheets("Sales")
With ObjSht
.Cells(IntC1, 19) = (Rst5![Model])
.Cells(IntC1, 20) = (Rst5![jan])
.Cells(IntC1, 21) = (Rst5![feb])
.Cells(IntC1, 22) = (Rst5![mar])
.Cells(IntC1, 23) = (Rst5![apr])
.Cells(IntC1, 24) = (Rst5![may])
.Cells(IntC1, 25) = (Rst5![jun])
.Cells(IntC1, 26) = (Rst5![jul])
.Cells(IntC1, 27) = (Rst5![aug])
.Cells(IntC1, 28) = (Rst5![sep])
'.Cells(IntC1, 29) = (Rst5![Oct])
'.Cells(IntC1, 30) = (Rst5![nov])
'.Cells(IntC1, 31) = (Rst5![dec])
End With
IntC1 = IntC1 + 1
Rst5.MoveNext
Loop
Rst5.Close
'=====================================================
Set Rst6 = Dbs.OpenRecordset("QrySalesbyChannelDlr")
Rst6.MoveFirst
IntC1 = 18
Do Until Rst6.EOF
Set ObjSht = ObjWkb.Worksheets("Data")
With ObjSht
.Cells(IntC1, 2) = (Rst5![Model])
.Cells(IntC1, 3) = (Rst5![jan])
.Cells(IntC1, 4) = (Rst5![feb])
.Cells(IntC1, 5) = (Rst5![mar])
End With
IntC1 = IntC1 + 1
Rst6.MoveNext
Loop
Rst6.Close
'=====================================================
ObjWkb.SaveAs "W:\Maz Urban Science\Development\Test\" & Rst1![DealerNo] & "PerformanceReport-" & Format(Date, "dd mmm") & ".xls"
ObjWkb.Close True
Rst1.MoveNext
Loop
Rst1.Close
Set Rst1 = Nothing
Dbs.Close
Set Dbs = Nothing
Set ObjWkb = ObjXL.Workbooks.Open(FullDir)
ObjWkb.Close
Case vbNo
End Select
MsgBox ("All actions complete")
DoCmd.Hourglass False
DoCmd.SetWarnings True
End Sub