MushroomKing
Registered User.
- Local time
- Today, 13:32
- Joined
- Jun 7, 2018
- Messages
- 100
Hi guys!
I got a little issue with exporting.
When i export to an xls file, and one of the fields is a date field, excel will not format this as a date field.
Any ideas why or how i can solve it?
Help is much appriciated. Stuck here.
I got a little issue with exporting.
When i export to an xls file, and one of the fields is a date field, excel will not format this as a date field.
Any ideas why or how i can solve it?
Help is much appriciated. Stuck here.
Code:
Sub XferData2XL()
DoCmd.SetWarnings False
Dim sFile As String
Dim xl As Excel.Application
Dim rst As dao.Recordset, rst1 As dao.Recordset
Dim lngLast As Long
'strSQL = "SELECT KPICOLLECTIVE.* From KPICOLLECTIVE"
With CurrentDb.QueryDefs("KPICOLLECTIVE")
'first parameter
.Parameters(0) = [Forms]![stats_form]![startdate]
.Parameters(1) = [Forms]![stats_form]![enddate]
Set rst = .OpenRecordset
''''''rst1.Filter = "RegistrationDate=#" & Format(Me.startdate, "dd/mm/yyyy") & "#"
''''''Set rst = rst1.OpenRecordset
End With
sFile = "C:\filetest.xls"
'Set rst = CurrentDb.OpenRecordset(strSQL)
Set xl = CreateObject("excel.application")
With xl
.Workbooks.Open sFile
.Range("A1").Select
'.Selection.End(xlDown).Select 'goto bottom of data
lngLast = .Range("A" & xl.rows.Count).end(xlUp).Row
If lngLast = 65536 Then
MsgBox "Sheet is full"
GoTo ExitSub
End If
Range("A" & lngLast + 1).Select
'.ActiveCell.Offset(1, 0).Select 'next free row
.ActiveCell.CopyFromRecordset rst 'paste data
.ActiveWorkbook.Save
.Quit
End With
ExitSub:
Set xl = Nothing
Set rst = Nothing
DoCmd.SetWarnings True
DoCmd.Close acQuery, "KPICOLLECTIVE"
End Sub