Results 1 to 11 of 11
  1. #1
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727

    Start Date and End Date in one prompt window

    Right now I have this in the query criteria row:

    >=[Enter Start Date:] And <=[Enter End Date:]

    This makes two prompts pop up one at a time. I was wondering if there was a way to combine both start and end date boxes in one prompt so I can see what dates I decide to type side by side. Is this possible?

    Thanks.

  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,623
    No.

    Use a form for input of the parameters.
    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
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Hey June7,

    long time no see. That would be ideal but from what I remember it was difficult to do. Would you have a template or the code to do this for 2 unbound text boxes?

  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,623
    Not that difficult.

    Build form with unbound textboxes and a button. Code behind button Click event to open query object.

    Build query object that references the textboxes:

    SELECT * FROM tablename WHERE [datefield] BETWEEN Nz(Forms!formname!tbxStart, #1/1/1900#) AND Nz(Forms!formname!tbxEnd, #12/31/2900#);

    I don't use dynamic parameters in queries. I also would not open query object. I would open a form or report.

    DoCmd.OpenReport "report name", , , "[datefield] BETWEEN #" & Nz(Me.tbxStart, "1/1/1900") & "# AND #" & Nz(Me.tbxEnd,"12/31/2900") & "#"
    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
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Ok June7,

    I messed with your suggestion above for a while today and was not able to get it to work. I put the SELECT * FROM tablename.......etc... into the query criteria and it gave back some syntax errors which I did not understand so I tried messing with it a bit and got it to accept it. I think I changed it to something like this

    SELECT * (FROM [LICENSE] WHERE [Date Issued:] BETWEEN Nz(Forms![Permit Date Issued]![txtStart], #1/1/1900#) AND Nz(Forms![Permit Date Issued]![txtEnd], #12/31/2900#))

    Might have been slightly different but it was something to that effect. I just kept trying to move things or add things until it stopped giving me syntax errors or errors that said it needed brackets or parenthesis to close the expression or something.

    Anyway, after I finished this part I couldn't even open my split form anymore with the 2 unbound text boxes with the button that you told me to make. It said something about it can't reference 2 text boxes so to change the expression to refer to only 1 text box or something like that. Then it would have the stop all macros window. So could you explain what is going on here? And direct what to do next?

    Thanks.

  6. #6
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    What June7 gave you was the full query the filter criteria part of [Date Issued:] would be only: BETWEEN Nz(Forms![Permit Date Issued]!txtStart, #1/1/1900#) AND Nz(Forms![Permit Date Issued]!txtEnd, #12/31/2900#)

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    As hapm described, macro just needs the filter criteria part of the SQL. Are you using SearchForRecord macro? Since the macro is behind the form, might be able to simplify without the form name:

    Where Condition= ="[Date Issued] BETWEEN #" & Nz([txtStart], "1/1/1900") & "# AND #" & Nz([txtEnd], "12/31/2900") & "#"

    I don't use macros. In VBA:

    Me.Filter = "[Date Issued] BETWEEN #" & Nz(Me.[txtStart], "1/1/1900") & "# AND #" & Nz(Me.[txtEnd], "12/31/2900") & "#"
    Me.FilterOn = True
    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.

  8. #8
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    I would prefer to use VBA too so this is what I did.

    I put this code behind the filter button:
    Private Sub cmdFilter_Click()

    Me.Filter = "[Date Issued] BETWEEN #" & Nz(Me.[txtStart], "1/1/1900") & "# AND #" & Nz(Me.[txtEnd], "12/31/2900") & "#"
    Me.FilterOn = True

    End Sub

    Then I entered the start and end dates into the 2 unbound texts boxes I made. Then I clicked the filter button and this prompt comes up that says:
    Enter Parameter Value ? for the title of the small window and then it has Date Issued with a field box for me to type in with an ok and cancel button.

    So what do I do next?

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    The parameter prompt probably means something is misspelled. Based on your earlier post, should there be a colon at the end?

    [Date Issued:]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Thank you very much. I will try that.

  11. #11
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Worked like a charm. Thanks so much guys. I been trying to get this done for a long time.

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

Similar Threads

  1. Replies: 12
    Last Post: 01-23-2014, 03:24 PM
  2. Replies: 1
    Last Post: 06-26-2012, 08:19 PM
  3. Replies: 15
    Last Post: 04-06-2012, 10:57 AM
  4. Replies: 1
    Last Post: 07-07-2010, 04:22 PM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 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