Hi guys, I have my access data export to excel with the codes below,
Sub Refresh()
Const cstrPath As String = "P:\Common\Operation\Folder A\Combined Data.accdb"
Const cstrQuery As String = "Final Data"
Dim dbe As Object 'DAO.DBEngine '
Dim rs As Object 'DAO.Recordset '
Dim ws As Worksheet
Application.DisplayAlerts = True 'leave alerts on during testing '
Set dbe = CreateObject("DAO.DBEngine.120")
Set rs = dbe.OpenDatabase(cstrPath).OpenRecordset(cstrQuery)
If Not rs.EOF Then
Set ws = ThisWorkbook.Sheets("Test")
ws.Range("A1").CopyFromRecordset rs
End If
rs.Close
Application.DisplayAlerts = True
End Sub
But, dates are display wrongly. Dates that are 2021 are now all 2025 and days are 1 day ahead.
Where is it wrong?
Please help!
Sub Refresh()
Const cstrPath As String = "P:\Common\Operation\Folder A\Combined Data.accdb"
Const cstrQuery As String = "Final Data"
Dim dbe As Object 'DAO.DBEngine '
Dim rs As Object 'DAO.Recordset '
Dim ws As Worksheet
Application.DisplayAlerts = True 'leave alerts on during testing '
Set dbe = CreateObject("DAO.DBEngine.120")
Set rs = dbe.OpenDatabase(cstrPath).OpenRecordset(cstrQuery)
If Not rs.EOF Then
Set ws = ThisWorkbook.Sheets("Test")
ws.Range("A1").CopyFromRecordset rs
End If
rs.Close
Application.DisplayAlerts = True
End Sub
But, dates are display wrongly. Dates that are 2021 are now all 2025 and days are 1 day ahead.
Where is it wrong?
Please help!