Results 1 to 3 of 3
  1. #1
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112

    How to query using form field as search criteria?

    Hi,
    I have a table that stores attendance record of students. It has 3 fields:
    1) Autonumber: Primary key (identifies each record in attendance field)
    2) Number:fkStudentID (key that links it to another table which stores the students' particulars like name, address, etc.)
    3) DateAndTime: SessionDate (stores the date of students' attendance record)
    4) Number: SessionID (stores the session that student attendant on the SessionDate)

    I will like to create a form that allows the user to view attendance records based on 3 criteria:
    1) Student's name (which I'll convert to fkStudentID)
    2) Date (SessionDate)
    3) Session (SessionID)

    E.g. the user can choose to search for all students that attended a particular session on a particular day. He'll leave the name field blank, and enter the date and sessionID and the result should display all students in that class.

    Or he could query all sessions attended by a particular student. He'll enter the name field, and leave the date and session blank.

    So in summary the user can choose to use any or all of the search criteria, and any combination in between.

    On my form, the user can enter the criteria on 3 visible text boxes. Once he hits the search button I will use VBA to process the data in the visible text boxes into a format suitable for the query to use. This will be stored on 3 invisible text boxes which are actually linked to the query's Criteria field.

    The results will be displayed in a subform which takes its data source from the query.



    My questions:
    1) What should I enter into the Criteria field of the query for each of the fields (fkStudentID, SessionID, SessionDate)? Should I just point it to the hidden search criteria fields on the form, or use something like this:

    Like "*" & Form.StudentIDCriteria & "*" (<-- I realize this will also show up results I might not want. E.g. 302 will also display 3021 or 1302.)

    So I don't know what to use.

    2) Secondly, can some kind soul give me some examples of data I should enter into the query criteria and the search criteria boxes on the form so this will work? I tried different combinations with no success. I'm guessing I need to format the data in the form fields somehow.

    Thanks!

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    There is a free video tutorial at this site that may give you some ideas.
    http://www.datapigtechnologies.com/f...earchform.html

  3. #3
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Thank you!

    Btw I also found a very good search form example on Allen Browne's site and am sharing it for anyone who's interested.

    http://allenbrowne.com/ser-62.html

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

Similar Threads

  1. Query criteria fields flooded after search
    By a12ctic in forum Queries
    Replies: 1
    Last Post: 06-27-2011, 06:25 PM
  2. Replies: 9
    Last Post: 05-05-2011, 02:05 PM
  3. Search By Criteria - Flexible Criteria Fields
    By lilanngel in forum Access
    Replies: 0
    Last Post: 03-16-2011, 06:25 PM
  4. search criteria in a form fails!
    By maxbre in forum Programming
    Replies: 2
    Last Post: 12-01-2010, 06:21 AM
  5. Replies: 3
    Last Post: 06-03-2009, 07:15 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