Search code examples
datecriteriabetween

SQL Query between date with more criteria (VBA Excel - Acess)


first post here. I learn excel vba by myself and I have a doubt I think u guys can help me. I have a sql query that searchs my database (Access) Between two dates.

SQL = "Select * From Financeiro Where Data Between #" & Format(Range("DB_Financeiro_DataInicial"), "MM/DD/YYYY") & "# and #" & Format(Range("DB_Financeiro_DataFinal"), "MM/DD/YYYY") & "#" & "Order By Data"

But I want to add another criteria in this same line code, for example, I want to search specifics vet names in my database between to dates. Can u guys help me to do it? Since I've been learning by myself in 7 months, there are some things that I don't know how to fix yet.

'Financeiro' is my database in access, since i'm brazilian, it's in portuguese. 'DB_Financeiro_Data' is a named cell in my sheet that receives the date information


Solution

  • Try "AND":

    SQL = "Select * From Financeiro Where Data Between #" & Format(Range("DB_Financeiro_DataInicial"), "MM/DD/YYYY") & "# and #" & Format(Range("DB_Financeiro_DataFinal"), "MM/DD/YYYY") & "# AND VetName Like '%" & Range("DB_Financeiro_Pesquisa") & "%' Order By Data;"