I am trying to run a query from within Excel VBA with variables from the Excel, but Access is turning my dates into US format:
Sub upload()
Last = ActiveSheet.UsedRange.Rows.Count
Dim LastOrderDate As Date
Dim LastOrderDateYear As Integer
Dim LastOrderDateMonth As Integer
Dim LastOrderDateDay As Integer
FirstOrderDate = Range("D" & Last)
FirstOrderDDate = DateSerial(Year(FirstOrderDate), Month(FirstOrderDate), Day(FirstOrderDate))
'Import Data to Benji's Ecommerce Database
ssheet = Application.ActiveWorkbook.FullName
Set acApp = CreateObject("Access.Application")
acApp.OpenCurrentDatabase ("X:\ECommerce Database.accdb")
acApp.Visible = True
acApp.UserControl = True
acApp.DoCmd.RunSQL "DELETE * FROM [OrdersDetailed] WHERE [OrderDate] >= #" & FirstOrderDDate & "#"
acApp.CloseCurrentDatabase
acApp.Quit
Set acApp = Nothing
End Sub
So for instance, with the variable 01/03/2017, it uses 03/01/2017 and deletes everything past 3rd Jan 2017, instead of the desired 1st Mar 2017.
I have checked my date display settings on my computer, and as far as I can see my region is UK and date format is UKs, I have never seen US style dates ever on my comp!
What is going on here, and how can I solve it?
Thanks,
Benji
FORMAT(FirstOrderDate,"dd/mm/yyyy)- PeterT