Hello cute_stuff,
In Excel (and Access, for that matter), dates are stored as floating point numbers. 40524 happens to be
12 Dec 2010, so '12 / 12' becoming 40524 makes sense.
Generally speaking, I avoid exporting reports from Access to Excel, because of the issues you raise above,
and more. Instead, I will typically open a recordset in VBA, and copy the recordset into Excel, and then
format the worksheet as desired.
Sub ExportToExcel()
Dim rs AS DAO.Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object
Dim Counter As Long
Const SaveToPath As String = "c:\Results\Report_"
Const QueryName As String = "NameOfQuery"
Set rs = CurrentDb.OpenRecordset(QueryName)
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlWb = xlApp.ActiveWorkbook
Set xlWs = xlWb.Worksheets(1)
With xlWs
For Counter = 0 To rs.Fields.Count - 1
.Cells(1, Counter + 1) = rs.Fields(Counter).Name
Next
.Cells(2, 1).CopyFromRecordset rs
End With
xlWb.SaveAs SaveToPath & Format(Now, "yyyymmdd") & ".xls"
xlWb.Close False
xlApp.DisplayAlerts = True
Set xlWs = Nothing
Set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing
rs.Close
Set rs = Nothing
MsgBox "Done"
End Sub
Regards,
Patrick