473,698 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching 4 fields (using 1 or many or all)

1 New Member
Hi,

I have a table called applicants

There is a form also called applicants which I use to view / edit the data.

On my main dashboard form which is where all of the main options are for the database (also the startup form) I have 4 search boxes which are called:

First Name
Last Name
Company Name
Post Code

I also used to have two additional search fields which were Applicant Ref and Telephone Number. I had to break these away from the main search as a secondary search feature on the form as I couldnt get the VB code that I had to get over the fact that the last 2 fields are Integer, even though the phone number is text :/

So here is my VB for all 6 search boxes, remember I have removed Applicant_ref and phone_number from the senerio, but when I just delete the lines related to the 2 Ive removed I get errors.

VB:

Private Sub Search_Go_Click ()

Dim strCriteria As String

If Not IsNull(Me.lastn ame) Then
strCriteria = "[Last_name] = '" & Me.lastname & "' AND "
End If

If Not IsNull(Me.PostC ode) Then
strCriteria = strCriteria & "[Post_code] = '" & Me.PostCode & "' AND "
End If

If Not IsNull(Me.Phone Number) Then
strCriteria = strCriteria & "[Telephone_numbe r] = '" & Me.PhoneNumber & "' AND "
End If

If Not IsNull(Me.first name) Then
strCriteria = strCriteria & "[First_name] = '" & Me.firstname & "' AND "
End If

If Not IsNull(Me.Compa ny) Then
strCriteria = strCriteria & "[Company] = '" & Me.Company & "' AND "
End If

If Not IsNull(Me.appli cantRef) Then
strCriteria = strCriteria & "[Applicant_ref] = '" & Me.applicantRef & "' AND "
End If

strCriteria = Left(strCriteri a, Len(strCriteria ) - 5)

DoCmd.Minimize

DoCmd.OpenForm "Applicants ", acNormal, , strCriteria
End Sub

*************** *************** ************
If I just remove the lines related to applicantRef or phone number then it works the first time I run it, then when attempting to search again, I get no results.

Thank you in advance.
Sep 27 '08 #1
1 1299
PianoMan64
374 Recognized Expert Contributor
Hi,

I have a table called applicants

There is a form also called applicants which I use to view / edit the data.

On my main dashboard form which is where all of the main options are for the database (also the startup form) I have 4 search boxes which are called:

First Name
Last Name
Company Name
Post Code

I also used to have two additional search fields which were Applicant Ref and Telephone Number. I had to break these away from the main search as a secondary search feature on the form as I couldnt get the VB code that I had to get over the fact that the last 2 fields are Integer, even though the phone number is text :/

So here is my VB for all 6 search boxes, remember I have removed Applicant_ref and phone_number from the senerio, but when I just delete the lines related to the 2 Ive removed I get errors.

VB:

Private Sub Search_Go_Click ()

Dim strCriteria As String

If Not IsNull(Me.lastn ame) Then
strCriteria = "[Last_name] = '" & Me.lastname & "' AND "
End If

If Not IsNull(Me.PostC ode) Then
strCriteria = strCriteria & "[Post_code] = '" & Me.PostCode & "' AND "
End If

If Not IsNull(Me.Phone Number) Then
strCriteria = strCriteria & "[Telephone_numbe r] = '" & Me.PhoneNumber & "' AND "
End If

If Not IsNull(Me.first name) Then
strCriteria = strCriteria & "[First_name] = '" & Me.firstname & "' AND "
End If

If Not IsNull(Me.Compa ny) Then
strCriteria = strCriteria & "[Company] = '" & Me.Company & "' AND "
End If

If Not IsNull(Me.appli cantRef) Then
strCriteria = strCriteria & "[Applicant_ref] = '" & Me.applicantRef & "' AND "
End If

strCriteria = Left(strCriteri a, Len(strCriteria ) - 5)

DoCmd.Minimize

DoCmd.OpenForm "Applicants ", acNormal, , strCriteria
End Sub

*************** *************** ************
If I just remove the lines related to applicantRef or phone number then it works the first time I run it, then when attempting to search again, I get no results.

Thank you in advance.
Hey icsnetuk,

The reason that you're having this problem is, you're opening a open with a filter applied. If you run that process again based on that filtered form, you are filtering your filtered data. Of course your result is going to blank. There is no way for any field to have two values at the same time.

What you're going to need to do is simply close the form, and open a new one with the new filter that you want.

Hope that helps,

Joe P.
Sep 27 '08 #2

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

Similar topics

4
2757
by: Michi | last post by:
I was wondering what the best solution is for making large numbers of TEXT (or BLOB?) fields searchable. For example, if I have a forum, what is the best way to be able to search for specific words? How about exact phrases? I saw a solution where all words are preindexed in a "dictionary" like table and then another table stores the word matches. That seems really fast, but it has two major problems: 1) it can't do exact matches, and 2)...
1
2413
by: Robert Oschler | last post by:
I read a while back that MySQL will only use one index per query. (If this is not so, please tell me and point me to a doc that gives a good explanation of MySQL's current index usage policy). I'm using MySQL 4.2.x. Here's my dilemma. 1) --------- I have two tables that have records with a FULLTEXT index text field in each of them. The problem is the relationship between the tables is a
8
1565
by: Stuart Clark | last post by:
Hello, I haven't done much with ASP but now I'm giving it a go! However, I'd like to ask if anybody knows if what I need to do is possible. I have a database with a lot of tables. Each table represents a customer. As customers come and go, so tables will be added and removed. I need to create a search utility that will search all tables for (e.g.) a customer name. I'm learning ASP so I'm not that advanced, but
2
1683
by: Tim Pollard | last post by:
Hi I'm hoping someone can help me with an access problem I just can't get my head around. I normally use access as a back end for asp pages, just to hold data in tables, so queries within access are a mystery to me, but I can't think of any other way of dealing with the problem. I have six tables in my db: tblCompanies (list of companies, primary key CompanyID) tblOffices (list of office buildings including what company owns/uses
3
2089
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
33
2496
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following criteria: I have a list of about 100 numbers which correspond to the ID field and also another 40 say numbers corresponding to the numbers in the PRODUCT field. I want to show the rows that correspond to both these criteria.
11
3439
by: TheDataGuy | last post by:
Using MS ACCESS 2002 I developed a FORM, and within that FORM, I created and added a SEARCH BUTTON, and then I created a SUB-FORM, so that when an the END USER clicks on the FORM it will POP-UP the SUB-FORM, and in that SUB-FORM I added all the FIELDS of the information I wanted to view. The SUB-FORM was created to do the actual SEARCHING. However, when I want to search a RECORD and I type in DATA of a specific RECORD into the FIELDS in...
7
4537
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent records. Should I design a new form for this or can I somehow make this work in the same form. Thanks in advance, john
0
1440
by: Kassimu | last post by:
Hi guys out there, There is this database Iam creating, I have a table with 40 fields among which there are Date/time, Text, Number, Memo and Yes/No fields and I have created the form bound to that tabe. I have also created Unbound form (for searching purpose) which is similar in layout with the bound one; in this search form the user will fill-in the keywords in as many text boxes as he wish to narrow down the search. The search results are...
0
8680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.