Results 1 to 3 of 3
  1. #1
    Rustin788 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    47

    Ignore Date Range If Blank

    Hey,

    I am creating a form for someone so they can pull up customer information. I have it set up so they can search by Sales Order #, Customer, or just put in a date range. My question is; is there a way set up the date fields so that if they are blank they are ignored when it runs the query. Right now if I do not include dates when searching it returns just a blank query. Currently in the query I have: Between [Forms]![Form Lookup]![BegOrd] And [Forms]![Form Lookup]![EndOrd].

    Thanks for any help.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Test all controls for a possible filter...

    Code:
    dim sSql as string, sWhere as string
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
    
        'remove 1st And
    sWhere= mid(sWhere,4)
    sSql = "SELECT * FROM tblCompany WHERE "
    sSql = sSql & sWhere
    frmResults.Recordsource = sSql

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    Between Nz([Forms]![Form Lookup]![BegOrd], #1/1/1929#) And Nz([Forms]![Form Lookup]![EndOrd], #12/31/2029#)

    Using appropriate dates that would include all your data.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 09-11-2013, 09:49 AM
  2. Replies: 1
    Last Post: 03-06-2013, 10:30 AM
  3. Replies: 3
    Last Post: 07-18-2012, 10:13 PM
  4. Ignore blank on query expression.
    By zero3ree in forum Access
    Replies: 3
    Last Post: 06-11-2012, 11:22 AM
  5. Date Range Report with Multiple Date Fields
    By StevenCV in forum Reports
    Replies: 13
    Last Post: 02-29-2012, 08:29 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