Results 1 to 11 of 11
  1. #1
    hockeyman9474 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Location
    Manalapan, NJ
    Posts
    45

    Open Query From Form Data

    I have a form with a few different boxes for user input. One of which is a combobox. There is a button on a form that triggers a query. The information that is queried is what the user has entered into the control boxes on the form. The user can enter information into as many or as little fields as they wish, with at least one field being required. I have coded the criteria field on the query with (i.e. =[FORMS]![MainMenu]![CarLine]). So far it works fine. I have also coded other criteria fields in the query the same way (i.e. =[FORMS]![MainMenu]![PartNum]). If carline is filled in and partnum is left blank, then my query returns no data.

    I think I need an iif statement that returns a wild card(*) if left blank.

    can someone assist?

  2. #2
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    I think:

    =[FORMS]![MainMenu]![PartNum] & "*"

    so that if [PartNum] is nothing then it will add "*" (everything)

  3. #3
    hockeyman9474 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Location
    Manalapan, NJ
    Posts
    45
    Seems Logical but let's assume I use logic on both boxes and fill none of the boxes in, then it should return all records correct? That's what I did to test, and received no Data. I remember reading something similar in regards to passing variables to SQL and using LIKE in there. I decided that that approach was too complicated and to only link to SQL and do all the querying on access front end. I believe LIKE is a SQL keyword. Can't be used in Aceess, can it?

  4. #4
    hockeyman9474 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Location
    Manalapan, NJ
    Posts
    45
    BTW my coding looks like this:
    IIf([Forms]![MainMenu]![PartNum]="","*" & [Forms]![MainMenu]![PartNum] & "*",[Forms]![MainMenu]![PartNum])

  5. #5
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    So what exactly are you trying to do?

    Yes you can use Like in access, I do it ALL the time, yes you can do it in the SQL view but also the Design view.

    In the 'Field:' row in the deisng view you can add
    Name: Like [Forms]![MainMenu]![PartNum] & "*"

    What are you trying to do with IIF?

  6. #6
    hockeyman9474 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Location
    Manalapan, NJ
    Posts
    45
    I saw an example somewhere using iif to follow this logic:

    if the field is blank/null(whichever it may be)then search all records.

    By doing this, I can search records based on all user input fields filled in or not. More specifically:

    I have 4 fields:
    1. Carline
    2. Accessory Code
    3. Part Number
    4.PO Number.
    The user can enter any or all into these boxes on a form and click a submit button. A query will take this the user input and search a table that is actually a linked table to a SQL DB.

  7. #7
    hockeyman9474 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Location
    Manalapan, NJ
    Posts
    45
    can't add that data to criteria field. Huh?

  8. #8
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    Not the croteria field, the "Field" field, where the names go, this goes into the SQL as the SELECT

  9. #9
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    Alright sorry didn't see the fist post

    Assuming you have a form named MainMenu
    And unbound text boxes, with names:
    Carline
    PartNum
    PONum
    ACode

    Make a query: Add the table you want to use: Double click on all the fields you want to show up.

    In the Criteria fields add
    Like [Forms]![MainMenu]![Carline] & "*"
    to any of the fields that you are searching though

    See what happens, I'm pretty sure this will work

  10. #10
    hockeyman9474 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Location
    Manalapan, NJ
    Posts
    45
    Let me ask you, given the information that I supplied, how would you approach?

  11. #11
    hockeyman9474 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Location
    Manalapan, NJ
    Posts
    45
    oh wait I think it worked by putting like in the criteria field. I'll play around from there. Thanks for your help

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

Similar Threads

  1. Open form to enter data
    By bharatdubole in forum Forms
    Replies: 2
    Last Post: 12-02-2012, 11:24 PM
  2. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  3. Replies: 3
    Last Post: 11-09-2011, 09:45 AM
  4. Replies: 1
    Last Post: 11-03-2011, 05:45 AM
  5. OPen Form to add data
    By joemills62 in forum Forms
    Replies: 3
    Last Post: 06-17-2011, 10:14 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