- In the ReportGeneration Query, specify the Criteria as follows:
- Like [Enter Number:] & "*"
- Change
- qdf.Parameters(0) = Like 1* TO qdf.Parameters(0) = "1"
- It seems that you are attempting to Run a SELECT Query. If this is the case, you cannot do this via the Execute Method of a QueryDef Object.
Hi ADezil,
Thanks for your reply. I tried what you recommended. An input box pops up when i run the code and it says "Enter number: ". subsequently when i enter '1' everythign from that point on works fine.
But still it seems we're having trouble with the qdf.Parameters(0) = "1" line. Any suggestions? You are right, it's a select query that I'm trying to export to Excel. If the code will make it more clear:
Thanks,
Ronald
Option Compare Database
Option Explicit
Sub ReportSFBayArea()
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim objXLApp As Object
Dim folderpath As String
Dim TemplateName As String
Dim Timecode As Integer
Dim Yr As Integer
Dim Qtr As Integer
Dim x As Integer
Dim y As Integer
Dim Area As Integer
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("ReportGeneration")
Set objXLApp = CreateObject("Excel.Application")
MsgBox ("This command will export the data to an Excel File for report generation. Afterwards, proceed to run the Macro 'GenerateReport' in Excel")
qdf.Parameters(0) = "1"
folderpath = "C:\HousingMarketReport\Reports\"
TemplateName = "Charting source codes.xls"
objXLApp.Workbooks.Open (folderpath & TemplateName)
objXLApp.Application.Visible = True
On Error Resume Next
Kill (folderpath & "Temp.xls")
objXLApp.ActiveWorkbook.SaveAs folderpath & "Temp.xls"
objXLApp.ActiveWorkbook.Close savechanges:=False
objXLApp.Application.Quit
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ReportGeneration", "c:\HousingMarketReport\Reports\Temp.xls"
objXLApp.Application.DisplayAlerts = False
objXLApp.Application.Visible = True
objXLApp.Workbooks.Open (folderpath & "Temp.xls")
objXLApp.Worksheets("sheet1").cells.Delete
objXLApp.Worksheets("sheet1").Delete
x = 1
y = 1
Do While objXLApp.cells(x, y) <> "TimeCode" And IsEmpty(objXLApp.cells(x, y)) = False
y = y + 1
Loop
Do
x = x + 1
Loop While CInt(objXLApp.cells(x + 1, y)) > CInt(objXLApp.cells(x, y)) And IsEmpty(objXLApp.cells(x + 1, y)) = False
Timecode = CInt(objXLApp.cells(x, y))
Qtr = Timecode Mod 4
If Qtr = 0 Then Qtr = 4
Yr = (Timecode - Qtr) / 4
On Error Resume Next
Kill (folderpath & Yr & "Q" & Qtr & "Report.xls")
objXLApp.ActiveWorkbook.SaveAs folderpath & Yr & "Q" & Qtr & "Report.xls"
Kill (folderpath & "Temp.xls")
Set objXLApp = Nothing
Set qdf = Nothing
Set dbs = Nothing
DoCmd.Quit
End Sub