Results 1 to 2 of 2
  1. #1
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167

    Form and Query

    Hi,

    I have two questions:



    First, I am trying to get a query to return records between a certain date range. In the form I have DateFrom and DateTo unbound text boxes from which faculty select the date range. I know I have done this before, but I cant figure out how to create a field name and write the criteria for the source query in design mode! I tried [Form]![FormName]![DateFrom]<[Form]![FormName]![DateTo] in the criteria but I can't seem to write a valid field name that doesn't alter the criteria in some way...

    Second, in the same form, faculty enter the StudentID for the student they wish to get records for. How do I write the code to show a msgbox when there is no such ID in the event they enter an StudentID incorrectly.

    Thanks in advance.

    Take care,

    Daryl

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    You have two different SQL criteria:
    Code:
    [DateFrom] <= [MyTable].[MyDateField] 
    AND 
    [DateTo] >= [MyTable].[MyDateField]
    So, in query design, you can have one criteria line for MyDatefield that says
    Code:
    >= Form!FormName!DateFrom AND <= Form!FormName!DateTo
    Optionally, you can put square braces around Form, Formname, and the control names. Mandatory if you use spaces in your form or control names.

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

Similar Threads

  1. Replies: 7
    Last Post: 06-10-2013, 12:40 PM
  2. Replies: 2
    Last Post: 01-30-2013, 07:34 PM
  3. Replies: 3
    Last Post: 01-15-2013, 01:58 PM
  4. Replies: 1
    Last Post: 06-09-2012, 05:44 PM
  5. Replies: 7
    Last Post: 05-02-2012, 08:04 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