yes i have tried both.
1. i use
Code:
DoCmd.OutputTo acOutputQuery
Code:
DoCmd.TransferSpreadsheet acExport
its going well but in that both cmd i can't use i.e Test.xls as my templated
2 also is use
Code:
Public Function ExportRequest() As String
On Error GoTo err_Handler
' Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Dim sTemplate As String
Dim sTempFile As String
Dim sOutput As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sSQL As String
Dim lRecords As Long
Dim iRow As Integer
Dim iCol As Integer
Dim iFld As Integer
Const cTabTwo As Byte = 3
Const cStartRow As Byte = 11
Const cStartColumn As Byte = 1
DoCmd.Hourglass False
' set to break on all errors
Application.SetOption "Error Trapping", 0
' start with a clean file built from the template file
sTemplate = CurrentProject.Path & "\SHOCTemplate.xls"
sOutput = CurrentProject.Path & "\SHOC.xls"
If Dir(sOutput) <> "" Then Kill sOutput
FileCopy sTemplate, sOutput
' Create the Excel Applicaiton, Workbook and Worksheet and Database object
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sOutput)
Set wks = appExcel.Worksheets(cTabTwo)
sSQL = "select * from Technical"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(sSQL, dbOpenSnapshot)
If Not rst.BOF Then rst.MoveFirst
' For this template, the data must be placed on the 4th row, third column.
' (these values are set to constants for easy future modifications)
iCol = cStartColumn
iRow = cStartRow
'Stop
Do Until rst.EOF
iFld = 0
lRecords = lRecords + 1
Me.lblMsg.Caption = "Exporting record #" & lRecords & " to SHOC.xls"
Me.Repaint
For iCol = cStartColumn To cStartColumn + (rst.Fields.Count - 1)
wks.Cells(iRow, iCol) = rst.Fields(iFld)
If InStr(1, rst.Fields(iFld).Name, "Date") > 0 Then
wks.Cells(iRow, iCol).NumberFormat = "mm/dd/yyyy"
End If
wks.Cells(iRow, iCol).WrapText = False
iFld = iFld + 1
Next
wks.Rows(iRow).EntireRow.AutoFit
iRow = iRow + 1
rst.MoveNext
Loop
ExportRequest = "Total of " & lRecords & " rows processed."
Me.lblMsg.Caption = "Total of " & lRecords & " rows processed."
exit_Here:
' Cleanup all objects (resume next on errors)
On Error Resume Next
Set wks = Nothing
Set wbk = Nothing
Set appExcel = Nothing
Set rst = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
Exit Function
err_Handler:
ExportRequest = Err.Description
Me.lblMsg.Caption = Err.Description
Resume exit_Here
End Function
work well for the the templated but this function cant run with my query which contain some parameter
Code:
SELECT tblSHOC_Log.SN, tblSHOC_Log.SHOCRefNo, tblSHOC_Log.ObsDate, tblSHOC_Log.Zone, tblSHOC_Log.Facility, tblSHOC_Log.Project, tblSHOC_Log.SHOCReportedby, tblSHOC_Log.[Which Org?], tblSHOC_Log.[Type of Observation], tblSHOC_Log.[Type of Behaviour or Condition], tblSHOC_Log.[Describe the Intervention], tblSHOC_Log.[Describe the follow up action], tblSHOC_Log.[Follow up by:], tblSHOC_Log.[Event Report raised?], tblSHOC_Log.[Update JSA/RA?], tblSHOC_Log.SHOCStatus
FROM tblSHOC_Log
WHERE (((tblSHOC_Log.Zone)=[forms]![frmSHOC_Log]![CboZone])) OR (((tblSHOC_Log.SHOCStatus) Like "*" & [forms]![frmSHOC_Log]![CboStatus] & "*"));
and i got error too low parameter.
thanks for help me