VBA to ms access query date not working

rambans21

New Member
Joined
Nov 12, 2018
Messages
3
Hi

im hoping someone can help me with this because i am really struggling.. I am having issue with ".CommandText = Array( _ "SELECT * FROM Consolidated WHERE [Start Date]> '2019-01-01 00:00:00'")"

it seems to be working fine if i do the criteria on brand or anything else.. however it doesnt want to work on date it just comes up with error "application-defined or object-defined error"


I have tried many different formats of dates.


With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=C:\Users\Meme\AppData\Local\Microsoft\Windows\Tem" _
, _
"porary Internet Files\Content.MSO\AC2EDA4A.accdb;Mode=Share Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet O" _
, _
"LEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global " _
, _
"Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=Fals" _
, _
"e;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;J" _
, _
"et OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False" _
), Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdTable

.CommandText = Array( _
"SELECT * FROM Consolidated WHERE [Start Date]> '2019-01-01 00:00:00'")



.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
"example"
.Refresh BackgroundQuery:=False
End With


Thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Re: VBA to ms access query date not working.. please help!!

You can omit the Array bit and dates need the be surrounded by the # sign. I also assumed the time is irrelevant so I omitted it:
Code:
.CommandText = "SELECT * FROM Consolidated WHERE [Start Date]> #2019-01-01#"
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top