P
pokdbz
Here is my query that I am using which I want transferred:
SELECT PHQ.PHQDate, PHQ.PHQTOT
FROM PHQ
WHERE (((PHQ.SSN)=[Forms]![Form1]![SSN]));
I am using this below to transfer items to an Excel sheet. Where I have the
stars is where it is giving me an error. Here is the error:
Runtime error 3061
Too few parameters. Expected 1.
Is there something I have to do different because this is a query?
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim db As Database
Dim rs As Recordset
Dim intLastCol As Integer
Const conMAX_ROWS = 20000
Const conSHT_NAME = "PHQChartQuery"
Const conWKB_NAME = "C:\PHQChart.xls"
Set db = CurrentDb
Set objXL = New Excel.Application
'*************************************************
Set rs = db.OpenRecordset("PHQChartQuery", dbOpenSnapshot)
'*************************************************
With objXL
.Visible = True
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME)
If Not Err.Number = 0 Then
Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME
End If
Err.Clear
On Error GoTo 0
intLastCol = objSht.UsedRange.Columns.Count
With objSht
.Range(.Cells(1, 1), .Cells(conMAX_ROWS, _
intLastCol)).ClearContents
.Range(.Cells(1, 1), _
.Cells(1, rs.Fields.Count)).Font.Bold = True
.Range("A2").CopyFromRecordset rs
End With
End With
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
Set rs = Nothing
Set db = Nothing
SELECT PHQ.PHQDate, PHQ.PHQTOT
FROM PHQ
WHERE (((PHQ.SSN)=[Forms]![Form1]![SSN]));
I am using this below to transfer items to an Excel sheet. Where I have the
stars is where it is giving me an error. Here is the error:
Runtime error 3061
Too few parameters. Expected 1.
Is there something I have to do different because this is a query?
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim db As Database
Dim rs As Recordset
Dim intLastCol As Integer
Const conMAX_ROWS = 20000
Const conSHT_NAME = "PHQChartQuery"
Const conWKB_NAME = "C:\PHQChart.xls"
Set db = CurrentDb
Set objXL = New Excel.Application
'*************************************************
Set rs = db.OpenRecordset("PHQChartQuery", dbOpenSnapshot)
'*************************************************
With objXL
.Visible = True
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME)
If Not Err.Number = 0 Then
Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME
End If
Err.Clear
On Error GoTo 0
intLastCol = objSht.UsedRange.Columns.Count
With objSht
.Range(.Cells(1, 1), .Cells(conMAX_ROWS, _
intLastCol)).ClearContents
.Range(.Cells(1, 1), _
.Cells(1, rs.Fields.Count)).Font.Bold = True
.Range("A2").CopyFromRecordset rs
End With
End With
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
Set rs = Nothing
Set db = Nothing