Sir can you help me to transfer my Access Query to MS excel? i have a
command button on the form to export the parameter query named
"HVACWindwardQu ery" to excel spreadsheet and i got the codes from
searching on the internet and books but the problem is when i run the
command button "Export" it just only open the Blank Spreadsheet, no
data at all that it came from my query named "HVACWindwardQu ery" and
there's an error on it "Run-time error '3061': Too few parameters.
Expected 2." and when i open the VBA editor this is an error that is on
highlight in yellow:
Set objRST = Application.Cur rentDb.OpenReco rdset(strQueryN ame) ....can
you help me to solve this problem, here is the code that im using it
came from the book but its not working out:
and this is the SQL View:
Still searchin to solve this problem and i read it on the book it says:
The query requires parameters, it should be probably use an alternate
method of opening a query and that is an OpenRecordset method. I don't
know how to use or create a code for OpenRecordset pls try to give me a
code using OpenRecordset method of the QueryDef object to open a
parameter query and Transport my query named "HVACWindwardQu ery" into
Excel Spreadsheet or the best method code for this problem. In my Form
there is two(2) date to fill in and once you click the button it will
go to "HVACWindwardQu ery" and preview my Report and i created a button
again to Export the query to Excel but is not working at all it gives
me a blank spreadsheet. Pls help me... Thanks and god bless..
command button on the form to export the parameter query named
"HVACWindwardQu ery" to excel spreadsheet and i got the codes from
searching on the internet and books but the problem is when i run the
command button "Export" it just only open the Blank Spreadsheet, no
data at all that it came from my query named "HVACWindwardQu ery" and
there's an error on it "Run-time error '3061': Too few parameters.
Expected 2." and when i open the VBA editor this is an error that is on
highlight in yellow:
Set objRST = Application.Cur rentDb.OpenReco rdset(strQueryN ame) ....can
you help me to solve this problem, here is the code that im using it
came from the book but its not working out:
Code:
Private Sub cmdExport_Click()
Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
Dim xlWorkbook As Excel.Workbook
Dim acQuery As QueryDef
Dim objRST As Recordset
Dim strQueryName As String
strQueryName = "HVACWindwardQuery"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbook = xlApp.Workbooks.Add
Set objRST = Application.CurrentDb.OpenRecordset(strQueryName)
Set xlSheet = xlWorkbook.Sheets(1)
For lvlColumn = 0 To objRST.Fields.Count - 1
xlSheet.Cells(1, lvlColumn + 1).Value = _
objRST.Fields(lvlColumn).Name
Next
'Change the font to bold for the header row
xlSheet.Range(xlSheet.Cells(1, 1), _
xlSheet.Cells(1, objRST.Fields.Count)).Font.Bold = True
'Add a border to header row cells
With xlSheet.Range(xlSheet.Cells(1, 1), _
xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range(xlSheet.Cells(1, 1), _
xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range(xlSheet.Cells(1, 1), _
xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range(xlSheet.Cells(1, 1), _
xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet
.Range("A2").CopyFromRecordset objRST
.Name = Left(strQueryName, 31)
End With
Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
End Sub
Code:
SELECT [HVAC Windward Table].[EQUIPMENT / PM NUMBER], [HVAC Windward Table].[TAG NO#], [HVAC Windward Table].[FACILITY NUMBER], [HVAC Windward Table].[BUILDING / LOCATION], [HVAC Windward Table].[EQUIPMENT TYPE], [HVAC Windward Table].[FREQ PM], [HVAC Windward Table].DATE, [HVAC Windward Table].REMARKS, [HVAC Windward Table].[JOB PLAN], [HVAC Windward Table].[FILTER SIZE], [HVAC Windward Table].[WORK ORDER NO], [HVAC Windward Table].[REPORTED DATE], [HVAC Windward Table].[TAG NO], [HVAC Windward Table].[ANNEX/SUB-ANNEX], [HVAC Windward Table].[SPEC NO], [HVAC Windward Table].[JOB DESCRIPTION], [HVAC Windward Table].RATING, [HVAC Windward Table].[COMMENTS/ACTION], [HVAC Windward Table].[INSPECTOR NAME] FROM [HVAC Windward Table]WHERE ((([HVAC Windward Table].DATE)>=forms![HVAC Windward Form]!txtdatefrom And ([HVAC Windward Table].DATE)<=forms![HVAC Windward Form]!txtDateTo));
The query requires parameters, it should be probably use an alternate
method of opening a query and that is an OpenRecordset method. I don't
know how to use or create a code for OpenRecordset pls try to give me a
code using OpenRecordset method of the QueryDef object to open a
parameter query and Transport my query named "HVACWindwardQu ery" into
Excel Spreadsheet or the best method code for this problem. In my Form
there is two(2) date to fill in and once you click the button it will
go to "HVACWindwardQu ery" and preview my Report and i created a button
again to Export the query to Excel but is not working at all it gives
me a blank spreadsheet. Pls help me... Thanks and god bless..
Comment