joeythelips
IS-IT--Management
Hi,
I received some code yesterday from GHOLDEN re exporting a crosstab query to excel.
However, when i run the code, i get an error: 'TOO FEW PARAMETERS, EXPECTING 2'. When i debug, it points to the following line:
Set rst = db.OpenRecordset("Wind_Speeds_Graph", dbOpenDynaset)
I really need to resolve this urgently, and would really appreciate any help.
Thanks,
Joe
This is the code:
Public Sub Command1_Click()
Dim ExcelApp As New Excel.Application
Dim intColIndex As Integer
Dim intRowIndex As Integer
Dim intCounter As Integer
Dim db As database
Dim rst As Recordset
'Open query as recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Wind_Speeds_Graph", dbOpenDynaset)
With ExcelApp
'open excel with file D:Test
.Workbooks.Open "C:\Documents and Settings\obrienj\Desktop\wind_speeds_graph.xls"
.Visible = True
'Set start column and row
intColIndex = 0
intRowIndex = 5
'loop through recordset and write fields to cells
Do While Not rst.EOF
.Cells(intRowIndex, intColIndex + 1) = rst!QuestionCode
.Cells(intRowIndex, intColIndex + 3) = rst!Question
.Cells(intRowIndex, intColIndex + 3) = rst!AnswerCode
.Cells(intRowIndex, intColIndex + 4) = rst!Answer
intRowIndex = intRowIndex + 1
rst.MoveNext
Loop
'Close Excel
.ActiveWorkbook.Close True
.Quit
End With
rst.Close
Set rst = Nothing
Set ExcelApp = Nothing
End Sub
I received some code yesterday from GHOLDEN re exporting a crosstab query to excel.
However, when i run the code, i get an error: 'TOO FEW PARAMETERS, EXPECTING 2'. When i debug, it points to the following line:
Set rst = db.OpenRecordset("Wind_Speeds_Graph", dbOpenDynaset)
I really need to resolve this urgently, and would really appreciate any help.
Thanks,
Joe
This is the code:
Public Sub Command1_Click()
Dim ExcelApp As New Excel.Application
Dim intColIndex As Integer
Dim intRowIndex As Integer
Dim intCounter As Integer
Dim db As database
Dim rst As Recordset
'Open query as recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Wind_Speeds_Graph", dbOpenDynaset)
With ExcelApp
'open excel with file D:Test
.Workbooks.Open "C:\Documents and Settings\obrienj\Desktop\wind_speeds_graph.xls"
.Visible = True
'Set start column and row
intColIndex = 0
intRowIndex = 5
'loop through recordset and write fields to cells
Do While Not rst.EOF
.Cells(intRowIndex, intColIndex + 1) = rst!QuestionCode
.Cells(intRowIndex, intColIndex + 3) = rst!Question
.Cells(intRowIndex, intColIndex + 3) = rst!AnswerCode
.Cells(intRowIndex, intColIndex + 4) = rst!Answer
intRowIndex = intRowIndex + 1
rst.MoveNext
Loop
'Close Excel
.ActiveWorkbook.Close True
.Quit
End With
rst.Close
Set rst = Nothing
Set ExcelApp = Nothing
End Sub