UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Trying To Select With Multiple Conditions, Access 2016    
 
   
Vaupell
post Oct 11 2018, 08:52 AM
Post#1



Posts: 7
Joined: 6-September 18




Hi guys.

I'm trying to select data using a data range (which works) and now i'm expanding the query to also filter with a additional criteria.

This is the code, that works and i like to expand on.
CODE
Set rs = CurrentDb.OpenRecordset("SELECT * FROM ItemsDatabase WHERE NextInspection BETWEEN Date() AND Date() + " & WarningDate)


I would like to add a search criteria to this, so i'm attempting to add a "like" criteria.
What i'm trying to make work is this (TableFilter contains the columname, and the FilterString contains the like criteria)
CODE
Set rs = CurrentDb.OpenRecordset("SELECT * FROM ItemsDatabase WHERE NextInspection BETWEEN Date() AND Date() + " & WarningDate & " AND TableFilter Like FilterString")


Also tryed to switch them around

CODE
Set rs = CurrentDb.OpenRecordset("SELECT * FROM ItemsDatabase WHERE AND TableFilter Like FilterString AND NextInspection BETWEEN Date() AND Date() + " & WarningDate)


The error code does not help me.. Run-time error 3061, To few parameters, expected 2. But I'm unawhere of a second criteria for Like.

Any help guys
Go to the top of the page
 
nuclear_nick
post Oct 11 2018, 08:58 AM
Post#2



Posts: 1,625
Joined: 5-February 06
From: Ohio, USA


Is 'Filterstring' a parameter like 'WarningDate' is?

If so, try, for example, this...
CODE
Set rs = CurrentDb.OpenRecordset("SELECT * FROM ItemsDatabase WHERE NextInspection BETWEEN Date() AND Date() + " & WarningDate & " AND " & TableFilter & " Like '" & FilterString & "'")


The best way I've found to test these things is to set the SQL to a string variable first, then debug.print the string, copy and paste it into a blank query, and see if it works there.
This post has been edited by nuclear_nick: Oct 11 2018, 09:01 AM

--------------------
"Nuclear" Nick
____________
The top three reasons to hide code; 1) It's not your own. 2) It's your own, but it's so crappy you don't want anyone to see it. 3) The comments in your code would get you in a lot of trouble if ever made public.
Go to the top of the page
 
Vaupell
post Oct 11 2018, 09:18 AM
Post#3



Posts: 7
Joined: 6-September 18



You where 100% correct, thank you so much nuclear_nick

Appriciated, and btw it works.
Go to the top of the page
 
nuclear_nick
post Oct 11 2018, 10:21 AM
Post#4



Posts: 1,625
Joined: 5-February 06
From: Ohio, USA


Great! Glad I could help.

Good luck with your project!

--------------------
"Nuclear" Nick
____________
The top three reasons to hide code; 1) It's not your own. 2) It's your own, but it's so crappy you don't want anyone to see it. 3) The comments in your code would get you in a lot of trouble if ever made public.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd October 2018 - 11:49 PM