Results 1 to 4 of 4
  1. #1
    Gary Childress is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    34

    Trying to show all records when nothing shows up within a particular date range

    Trying to create a query criteria that will bring up all events within a date range. So here's what I have. I have two text boxes that are formatted for short date and have date pickers. The person entering the data can either use the date picker or just type in a short date like 2/1/15. I added the following criteria to the field in a query:

    Code:
    Between [Forms]![Switchboard]![Text501] And [Forms]![Switchboard]![Text502]
    This works fine for me unless I leave text501 and/or text502 blank. If I leave the two fields blank, then the form comes up but I get a blank form with no records. Ideally I'd like to have all records appear when the fields are left blank.



    Would this be possible? And if so what sort of code or expression would I put in the criteria box for the field in the query?

    Thank you.

  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,850
    It is helpful to readers to show your tables and relationships ( so we get some idea of the subject matter).

    Your code could make sure the user has populated the text boxes.
    You might research:
    the CDate function ---converts a string to a Date
    IsDate() function to ensure date field is valid eg no 48/3/2019
    check the textbox for a value

    iif (len(textfield & "")= 0, nothingEntered, check the date here)

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You could try using something like http://access.mvps.org/access/queries/qry0001.htm
    Code:
    Between ([Forms]![Switchboard]![Text501] Or [Forms]![Switchboard]![Text501 Is Null) And ([Forms]![Switchboard]![Text502] Or [Forms]![Switchboard]![Text502] Is Null)
    (I would give the controls better (more meaningful) names that the access default. "StartDate" vs "Text501"..... Which is more descriptive?)



    I do not use a WHERE clause in the query. I create the filtering clause in code. http://allenbrowne.com/ser-62code.html

    Depends on your VBA skills.

  4. #4
    Gary Childress is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    34
    Quote Originally Posted by ssanfu View Post
    You could try using something like http://access.mvps.org/access/queries/qry0001.htm
    Code:
    Between ([Forms]![Switchboard]![Text501] Or [Forms]![Switchboard]![Text501 Is Null) And ([Forms]![Switchboard]![Text502] Or [Forms]![Switchboard]![Text502] Is Null)
    (I would give the controls better (more meaningful) names that the access default. "StartDate" vs "Text501"..... Which is more descriptive?)

    I do not use a WHERE clause in the query. I create the filtering clause in code. http://allenbrowne.com/ser-62code.html

    Depends on your VBA skills.

    Thank you for the reply ssanfu. I tried the code you provided (inserted the missing bracket behind text501) but it still comes up with no records. Unfortunately my VBA skills are pretty much cut and paste only.

    @orange: My apologies. I'm attaching a pic of the relationships if that helps. Also the date search is going to be optional so if a user wants to search by another criteria then they can do that instead and leave the date fields blank. So I don't want to require the user to enter something in the date field if their search doesn't require it. Thanks.
    Attached Thumbnails Attached Thumbnails MS Access Relationship 3.gif  

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

Similar Threads

  1. Create records for date range
    By wnicole in forum Access
    Replies: 1
    Last Post: 10-03-2013, 09:02 AM
  2. Replies: 6
    Last Post: 07-10-2013, 07:39 AM
  3. Replies: 5
    Last Post: 07-05-2013, 11:16 AM
  4. Getting a date range to show on a report
    By recon2011 in forum Reports
    Replies: 3
    Last Post: 01-10-2012, 01:27 PM
  5. Criteria to show date range
    By Douglasrac in forum Queries
    Replies: 2
    Last Post: 03-24-2011, 03:58 PM

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