Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8053389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:49:41+00:00 2026-06-05T07:49:41+00:00

My table table1 has 3 fields: FName , LName , Phone . I am

  • 0

My table table1 has 3 fields: FName, LName, Phone. I am using Microsoft Access 2010 for running the SQL query. Some rows has empty / null phone values.

I have a VB form which accepts search parameters. A user can enter (FName and LName) or (Phone), but not both at the same time.

When I try:

SELECT table1.LName, table1.FName, table1.Phone
FROM table1
WHERE table1.LName Like ('*' & Forms!frmSearchMain!LName & '*') AND table1.FName Like ('*' & Forms!frmSearchMain!FName & '*')
ORDER BY table1.LName, table1.FName;

It gives me a list of user matching the given (FName and LName) parameters. It works fine.

Similarly, when I try:

SELECT table1.LName, table1.FName, table1.Phone
FROM table1
WHERE table1.Phone Like ('*' & Forms!frmSearchMain!Phone & '*')
ORDER BY table1.LName, table1.FName;

It gives me a list of user matching the given (Phone) parameter. It works fine too.

But, when I combine both these queries:

SELECT table1.LName, table1.FName, table1.Phone
FROM table1
WHERE table1.Phone Like ('*' & Forms!frmSearchMain!Phone & '*') AND table1.LName Like ('*' & Forms!frmSearchMain!LName & '*') AND table1.FName Like ('*' & Forms!frmSearchMain!FName & '*')
ORDER BY table1.LName, table1.FName;

It doesn’t give me the expected results.

I even tried OR condition between (FName and LName) and (Phone) search parameters. It doesn’t work. I have tried nz(frmSearchMain!Phone,"") for all the search params, % instead of *, but no luck so far.

I am new to the MS Access SQL Query format. I have used this type of queries a lot of times in MySQL. But I couldn’t get the expected results from this one.

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:49:42+00:00Added an answer on June 5, 2026 at 7:49 am

    I think it should be easier to sort this one out if we simplify it. So I arbitrarily decided to ignore LName for now, and do the searching based only on FName or Phone.

    In my version of frmSearchMain, I named the text box which holds the search target value for FName as txtSearchFName simply because I prefer to name the control differently than the record source field. Similarly, I chose txtSearchPhone for the Phone search target text box.

    Since I already had a table named Table1, I called mine tblKeerthiram instead.

    With those changes, this query gives me rows which match txtSearchFName or txtSearchPhone. If both txtSearchFName and txtSearchPhone are Null, the query return all rows from the table … which is what I hope you want.

    SELECT
        t1.id,
        t1.FName,
        t1.Phone
    FROM tblKeerthiram AS t1
    WHERE
               (t1.FName Like "*"
                   & [Forms]![frmSearchMain]![txtSearchFName]
                   & "*"
            OR [Forms]![frmSearchMain]![txtSearchFName] Is Null)
        AND
               (t1.Phone Like "*"
                   & [Forms]![frmSearchMain]![txtSearchPhone]
                   & "*"
            OR [Forms]![frmSearchMain]![txtSearchPhone] Is Null)
    ORDER BY t1.FName;
    

    A consequence of this approach is that, if both txtSearchFName and txtSearchPhone are non-Null, the query will return only the rows which match both. As I understood your description, that is not what you want. You want to search by only one or the other, not both at the same time.

    In that case I suggest you use the after update events for the two search text boxes to set the other Null when a non-Null value has been entered into one of them. I’m unsure how clear that sentence was, so just add this code to your form’s module. It will ensure that only one of the two text boxes will contain a non-Null value.

    Option Compare Database
    Option Explicit
    
    Private Sub txtSearchFName_AfterUpdate()
        If Not IsNull(Me.txtSearchFName) Then
            Me.txtSearchPhone = Null
        End If
    End Sub
    
    Private Sub txtSearchPhone_AfterUpdate()
        If Not IsNull(Me.txtSearchPhone) Then
            Me.txtSearchFName = Null
        End If
    End Sub
    

    Finally if that all works, then you only need to revise it to deal with LName. Hope that part won’t be too daunting. Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a table called analyzed in Microsoft Access. It has many fields
My SQL table has 2 fields that impact my problem: Priority as real, and
my table has the following fields videos |id| |average| |views| now i select some
Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products'
Imagine a table that has two fields, a smalltimedate and an int and about
Consider the following table which has the fields - id (int) and date_created (datetime):
I have a user table 'users' that has fields like: id first_name last_name ...
I have a table User which has the fields (id, first_name, middle_name, last_name). I
I have a simple table (lets call it Table1) that has a NVARCHAR field
I have a table that has multiple rows with the following fields: PersonName SongName

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.