Login | |
|
 |
RE: Searching by one or more fields - 7/11/2007 7:09:44 AM
|
|
 |
|
| |
Country73
Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
|
ehvbs beet me to it, but here's a different route. ' Value of 0 (Zero) is reserved as NO entry for that value ClientName = 0 JobType = 0 CreateDate = 0 ' Value of 1 is reserved for entry's made for the value IF vClientName.Value <> "" THEN ClientName = 1 IF vJobType.Value <> "" THEN JobType = 1 IF vCreateDate.Value <> "" THEN CreateDate = 1 SearchValue = ClientName & "," & JobType & "," & CreateDate SELECT CASE SearchValue CASE "0,0,0" 'All items left blank 'This is where you create your values to search on. 'Example: 'stWhere = "Client.ClientName Like'" & "%" & vClientName.value & "%" & "'" 'stWhere = stWhere & "AND Project.JobType Like'" & "%" & vJobType.value & "%" & "'" 'stWhere = stWhere & "AND Project.DateCreated>=" & "#" & vCreateDate.value & "#" & "" CASE "1,0,0" 'Search on vClientName.Value only CASE "1,1,0" 'Search on vClientName.Value AND vJobType.Value CASE "1,1,1" 'Search on vClientName.Value AND vJobType.Value AND vCreateDate.Value CASE "1,0,1" 'Search on vClientName.Value AND vCreateDate.Value CASE "0,1,1" 'Search on vJobType.Value AND vCreateDate.Value CASE "0,0,1" 'Search on vCreateDate.Value only CASE "0,1,0" 'Search on vJobType.Value only END SELECT MSODSC.RecordsetDefs.Item("ProjectClientFile Query").ServerFilter = stWhere
|
|
| |
|
|
|
 |
RE: Searching by one or more fields - 7/11/2007 7:36:49 AM
|
|
 |
|
| |
ebgreen
Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
|
It's true that the drawback to Select-Case is that it is binary. So every time that you add a new search field you double the number of cases. Right now with 3 fields you have 8 cases. With 4 fields you would have 16.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Searching by one or more fields - 7/11/2007 11:54:24 PM
|
|
 |
|
| |
Country73
Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
|
Thanks for that bit of insight, ebgreen and ehvbs. I have a couple of scripts put together, just like the Select Case I posted, but I know for a fact that the database they connect to will not change. One of the scripts I have this setup for will search a database that only lists: MachineType, RAM_Total, Deployment_Date (those are the only fields in the database). This database has been setup like this for over 3 years and if any modifications need to come about, then a whole new database will need to be created. So for "THIS" instance it would work fine. If your database has a lot more fields that could eventually be used to search against, then the Select Case method may not be the right choice. It really depends on the database you are setting this up for, and how much work you want to put into it. Just trying to throw some ideas out there so that there's a few choices as to how to handle different scenarios. P.S. I really like the way you threw this together: quote:
IF "" = Trim( vClientName.Value ) THEN ClientName = 0 ELSE ClientName = 1 I didn't even think about it that way. (Used to really drawing everything out pretty lengthy when creating my scripts so that others in my area can follow it pretty well without asking me too many questions about it)
< Message edited by Country73 -- 7/11/2007 11:58:02 PM >
|
|
| |
|
|
|
|
|