473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Recordset Findfirst with two criteria does not work

Both of the following statements work perfeclty when used separaty. I have tried a gazillion different combinations to concatenate them and Can't get
It to work, driving me insane:
Expand|Select|Wrap|Line Numbers
  1. Me.Recordset.FindFirst "Active = True"
  2. Me.Recordset.FindFirst "FullName Like '*" & txtNameSearch & "*'"
Thanks much for your help,

Alex
Feb 27 '15 #1

✓ answered by Rabbit

I'm not sure how your criteria got so far away from your original code. But this is what you need.
Expand|Select|Wrap|Line Numbers
  1. StrCriteria = "FullName Like '*" & txtNameSearch & "*' And [Active] = True"

8 2203
Rabbit
12,516 Expert Mod 8TB
I see two separate criterias, where's the one where you attempted to concatenate them?
Feb 27 '15 #2
Rabbit,

Thanks for your help, as stated I have tried many combinations, with and with out brackets, siuble quites in different areas, single quotes, etc... Inhave tried one in front of the other, same as above
Joined by "&" and by "and" with no success. I have also trued without success:

Dim rst as dao.recordset
Dim atrCriteria as String
StrCriteria = "[FullName='" & '*" & txtNameSearch & "*'" AND [Active] is True
rst.Findfirst strCriteria

Maybe I'm going about it the wrong way, but my ultimate goal is to perform a search of the FullName field supplied by searchbox, txtNameSearch, but only if the record's Active (checkbox) field is True...

Again your help us GREATLY appreciated,

Alex
Feb 27 '15 #3
Rabbit
12,516 Expert Mod 8TB
I'm not sure how your criteria got so far away from your original code. But this is what you need.
Expand|Select|Wrap|Line Numbers
  1. StrCriteria = "FullName Like '*" & txtNameSearch & "*' And [Active] = True"
Feb 27 '15 #4
Hi Rabbit, I had to make a slight mod to it, but it works like champ!, Thanks so much... I had been trying and changing things and researching for weeks, I guess it got messed up from there... In any case, I went back to my original code and that is where your suggestion worked perfectly in short I used:

Expand|Select|Wrap|Line Numbers
  1. Me.Recordset.FindFirst "FullName Like '*" & txtNameSearch & "*' And [Active] = True"
Thanks again for your help, really appreciate it, sure I'll be by again as more projects arrive.

Cheers!
Mar 2 '15 #5
NeoPa
32,556 Expert Mod 16PB
Alex, if you consider that the criteria you want is a string value passed to SQL to interpret then your first rule is to write code that results in a string value.

The fact is that your string and Rabbit's string are actually identical. You simply pass it to the FindFirst immediately where with Rabbit's code you'd pass the variable like so :
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "FullName Like '*" & txtNameSearch & "*' And [Active] = True"
  2. Me.Recordset.FindFirst strCriteria
One small benefit of the way Rabbit does it is that you can then view the contents of the string to see the intended value after it's been calculated and can thus check that it's exactly as anticipated. It's often recommended that people program that way for anything SQL based for that reason. Especially for those still relatively new to the skill.
Mar 2 '15 #6
@Rabbit
Hi Rabbit,

Sorry to bug ya with this again, but I've just been asked to add 7 more fields to this search string, AssetTag1, AssetTag2, AssetTag3, etc... But I cannot get it to work, I have tried placing double and single quotes as above around them, tried both the and/or, but no luck, I think I have the syntax wrong...

Please help, in advance thanks a mill,

Alex
Mar 30 '15 #7
Rabbit
12,516 Expert Mod 8TB
You haven't posted any of your code. Kind of hard to tell you what's wrong with the code when there's no code to look at.
Mar 30 '15 #8
@Rabbit
It's the same code you posted above, sorry about that... Although I have since figure out the issue and I got it working.

Thanks again for your usual help,

Alex
Mar 30 '15 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: cv | last post by:
Hello All, I have used MultipartRequest like the following to upload images. MultipartRequest multi = new MultipartRequest(request, "../webapps/coreprogram/dealerlogos", 1024 * 1024); It...
5
by: Paul | last post by:
The 2 statements below work perfectly when using them individually. But when I try to concatenate them, they don't. rst.FindFirst " = " & OldQuoteNumber rst.FindFirst " Is Null" Can someone...
3
by: wvhines | last post by:
Hello: I am an ambitious novice...I have a main form "frmGeneralContracting" that has a subform on it called "frmsubDeliverables" and I am trying to restrict editing if the current user's login...
3
by: iheartvba | last post by:
Hi Guys, thanks for the great work you are doing I am working on a database in MS Access and am trying to bring up the last receipt number in the recordset (its the primary key of the recordset)...
1
by: Newbie in ChiTown | last post by:
Here's my code: I am using MS Access and I am trying to update a table (InvoiceDetails) with data input by the user on a form. However, it does not update nor does it give me an error message. ...
5
Scott Price
by: Scott Price | last post by:
I'm not quite ready to give up on this yet... Using MS Access 2003, WinXP SP2. I have a listbox that I'm trying to get to highlight (select) a specific record using the GotFocus event (the...
1
patjones
by: patjones | last post by:
This is not a question, but rather an informational post about something I just solved. My issue was that I'm trying to use rst.FindFirst (str1 & " = '" & txtLastNameSearch.Value & "'") My...
4
by: ziccardi | last post by:
I'm trying to update a table with information from another table. The tables have 4 fields that should match to allow the update. Here is the code that is giving me a problem: With UpdtTrends...
5
Seth Schrock
by: Seth Schrock | last post by:
I'm using SQL in VBA to check if a checkbox is checked or not. I don't get any compilation errors, but when I run the code (On click event for a button), it says "Type mismatch" and doesn't error...
12
Seth Schrock
by: Seth Schrock | last post by:
I have a search form that allows the user to type in a customer name and it brings up all the records that are like the name the user typed in. The user then just double clicks on the record and it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.