Hello everyone,


I'm just starting to learn VBA Excel/Access and some SQL. I tried during hours to find a solution to my problem online. So far I didn't find a solution, so I'm turning to this forum to try and find some help. I'm probably doing something fundamentally wrong in my code because it just keep not working.


I'm trying to import a txt file, using this code.
Public sub IMPORT ()
Dim DATE1 as String


DATE1 = InputBox("Type in today's date using YYYYMMDD format")


DoCmd.TransferText transferType:=acImportDelim, TableName:="TREASURY_" & DATE1, FileName:="C:\Documents\AccessTEST\TREASURY_" & DATE1 & ".txt", hasfieldnames:=True

This works well but then I try to apply some filters and I just don't manage to have multiples filters at the same time.
I tried multiple things, first using an SQL query with the following code :
Dim SQLquery1 as String
SQLquery1 = "SELECT TREASURY_" & DATE1 & ".* " & _
"FROM "SELECT TREASURY_" & DATE1 & " & _
"WHERE ((("TREASURY_" & DATE1 & ".PORTFOLIO)='Portfolio_2' Or ("TREASURY_" & DATE1 & ".PORTFOLIO)='Portfolio_5') AND (("TREASURY_" & DATE1 & ".TRANSACTION_DATE) >" & DATE1 & "));"


DoCmd.runSQL SQLquery1

This does not work where as if I create a query and paste this code above (with DATE1 = 20190930 for example), it works.


Then I tried using the DoCmd.ApplyFilter with the following code :
DoCmd.Applyfilter , "[PORTFOLIO] = 'Portfolio_2'"
DoCmd.Applyfilter , "[TRANSACTION_DATE]>" & DATE1

This code works but it does not add up the conditions, it will first filter on Portfolio_2 and then on Transactions dates > today's date. I did not manage to filter on Portfolio_2 and Portfolio_5 aswell.


If anyone has an idea on why the SQL query is wrong or how to apply multiple filters using DoCmd.Applyfilter I'd gladly use the help.


Thanks for the help and sorry if my english is not very good.