Results 1 to 5 of 5
  1. #1
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659

    Using unbound form data in query not working

    I am trying to use 2 forms unbound textboxes to limit what data is viewed on a query. I have tested in my immediate window



    Code:
    ?[forms]!reportlist.form.txtStart
    1/1/2013
    ?[forms]!reportlist.form.txtend
    5/1/2013
    However when I use in my query

    Select * from tblentries where tblentries.bdate >= [forms]!reportlist.form.txtStart and <=[forms]!reportlist.form.txtend

    Bdate is always a date.

    I get data that falls outside the window im looking for.

    Is this an incorrect way to reference and restrict data?


    Thank you for your time

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Dynamic parameters in query are possible, just your syntax is wrong. Try:

    Select * from tblentries where tblentries.bdate BETWEEN Nz([forms]!reportlist.txtStart, #1/1/1900#) AND Nz([forms]!reportlist.txtend, #12/31/2900#)

    The Nz() function allows the query to still work if users neglect to input criteria.

    However, I NEVER use dynamic parameters in query. I prefer VBA to set Filter and FilterOn properties of form. Review: http://allenbrowne.com/ser-62code.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Ah BETWEEN!. I didn't even think of that.

    Is there any benefit to converting the dates to a long and doing the similar?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    I've never done that so I guess my answer is No.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Thank you for your help =).

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

Similar Threads

  1. Replies: 5
    Last Post: 07-07-2014, 09:29 AM
  2. Query on a Unbound form with Null Values
    By Kenny in forum Queries
    Replies: 2
    Last Post: 05-24-2012, 12:51 AM
  3. Unbound form for data filtering
    By alliandrina in forum Access
    Replies: 7
    Last Post: 05-21-2011, 05:19 PM
  4. Replies: 8
    Last Post: 02-03-2011, 09:51 AM
  5. Replies: 6
    Last Post: 12-01-2010, 06:52 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