Results 1 to 10 of 10
  1. #1
    AndreasPanayiotou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    21

    Customise Search Query

    Hello, i am new to the forum as you can guess as i sincirely have some issues with a query.
    Ok here is the details, one of the many tables that i have is named Inventory.

    SELECT Inventory.CategoryID, Inventory.BrandID, Inventory.ID, Inventory.FirstName, Inventory.LastName
    FROM Inventory
    WHERE (((Inventory.CategoryID) Like "*" & [Forms]![Inventory]![Category] & "*") AND ((Inventory.BrandID) Like "*" & [Forms]![Inventory]![Brand] & "*") AND ((Inventory.FirstName) Like "*" & [Forms]![Inventory]![Namee] & "*") AND ((Inventory.LastName) Like "*" & [Forms]![Inventory]![Surnamee] & "*"));



    I call this as a customise query because end-user have four fields to fill but none of that is neccesary.
    for example the fields are: Name,Surname,Category ,Brand
    User can fill what ever he wants and then can click the Search button for the query to work.
    My problem here is that i store info about users and about the hardwares that are related to them, but there hardware that they do not belong to any user and when the user search lets say for a Category name Keyboard and a Brand named Trust the query do not show any result.
    As query will show results only in hardwares that are related to user.
    I know what is the problem here, is because i have "AND" in all fields so in order the query to be corrert all fields must be true.
    So if a user is not related to a hardware the query wont work.
    My question here is what i can do for it ?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    If you're only looking for Inventory info related to a specific user, then how about something like
    Code:
    SELECT
    Inventory.*
    FROM
    Inventory
    WHERE
    ((Inventory.FirstName) Like "*" & [Forms]![Inventory]![Namee] &  "*") AND 
    ((Inventory.LastName) Like "*" &  [Forms]![Inventory]![Surnamee] & "*"));

    If the user is not related to hardware, nothing will be returned from the query.

  3. #3
    AndreasPanayiotou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    21
    Thanks for your reply, maybe i dident explain my self correctly.
    The search must search for user who are related as also for user who are not related.
    For example: as i said have four textbox/fields. , Name,Surname,Category ,Brand
    if i type the name the query will show the name that i had search,the surname as also the different categorys or brands.
    Now, if lets say i added a hardware the there is now user on it, that means i wont add any name or surname but i will add a category lets say keyboard and the brand would be microsoft.
    The search query wont find this result even if it is true becaue i do not have any name or surname on it.
    As you can read my SQL i have three "AND", that means four things must be true.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Right I understand your ANDs.

    Your question is still not clear to me.
    What exactly do you want? Can you give an example with some data to show the issue?

    If you have 1 table Inventory, where are you getting these "related things"? Where does becaue i do not have any name or surname on it. fit?

    I think you have a design problem. In very general terms you have

    People
    Things/Items
    Category
    Brand

    Seems you can Have a Thing that has a Brand and is assigned a Category, BUT may not be associated with a Person.

    If that is the case, then you have a data base structure issue.
    Are you familiar with Normalization?

    You may get some ideas from models here
    http://www.databaseanswers.org/data_models/index.htm

    see http://www.databaseanswers.org/data_...sets/index.htm for some ideas

  5. #5
    AndreasPanayiotou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    21
    i did normalize my table, i have a table named brand, as i have multiple items with the same name therefore i made a table of it ( 4 Normal Form) the brand table has the BrandId and Brandtype and BrandID is foreign key in the Inventory Table. Also i have a Category table that there is a categoryID and categoryType and foreign key on Inventory. The name and surname of the user is stored in the Inventory Table.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Can you post a jpg of your tables and relationships?

    Can you give an example with some data to show the issue?

    I have acc2003 so can not read/use an accdb file. Do you want to post a copy of your db with no personal info?
    Last edited by orange; 08-10-2012 at 12:11 PM.

  7. #7
    AndreasPanayiotou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    21
    Dear orange, check your email please. Thank you.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

  9. #9
    AndreasPanayiotou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    21
    i cant save it as mdb as i have some macro and codes that cannot be in mdb

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Ok post it to this forum ans seek help from someone with 2007 or 2010.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Search Query
    By sgray in forum Queries
    Replies: 7
    Last Post: 02-16-2012, 04:37 AM
  2. Help with search query
    By Sirius in forum Queries
    Replies: 0
    Last Post: 08-08-2011, 03:33 PM
  3. Search Query
    By convey2web in forum Queries
    Replies: 3
    Last Post: 11-08-2010, 02:27 PM
  4. Search with in a Query
    By AccessCodeMonkey in forum Queries
    Replies: 4
    Last Post: 03-09-2010, 03:16 PM
  5. yes/no search query
    By islandboy in forum Queries
    Replies: 7
    Last Post: 06-30-2009, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums