Results 1 to 6 of 6
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Can I use a Parameter on a Date/Time Field?


    I have a query I need to run based on a date time field. I want the parameters to be entered via a text boxes on a form, i.e. >= frm_Myform!txt_Begin_DateTime and <= frm_Myform!txt_End_DateTime
    My question is, how do I get the time portion of this entered into my form and use it in the query. I have tried several different ways without success.

    Any ideas?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This is one way:

    Code:
        strCriteria = "ActionDateTime Between #" & DateValue(Me.txtFromDate) + TimeValue(Nz(Me.txtFromTime, "0:00")) _
                    & "# And #" & DateValue(Me.txtToDate) + TimeValue(Nz(Me.txtToTime, "23:59")) & "#"
    Which is building a wherecondition for this technique:

    BaldyWeb wherecondition

    I'm also using the Nz() function to allow the user to leave the time textboxes empty.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Adapted for Query Window

    Thanks Paul,

    To avoid rebuilding the entire (very long) query in code I put this in the appropriate column in the criteria row in the Query module:
    Code:
    >=DateValue([Forms]![frm_DowntimeReasons]![txt_FromDate])+TimeValue([Forms]![frm_DowntimeReasons]![txt_FromTime]) And <=DateValue([Forms]![frm_DowntimeReasons]![txt_TillDate])+TimeValue([Forms]![frm_DowntimeReasons]![txt_TillTime]) 
    To my surprise it worked.

    Here's a bonus question. Is there any kind "time picker" similar to the Date Picker property in the text box?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I haven't used it but Brent is very sharp:

    http://www.utteraccess.com/forum/Tim...-t1454249.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    That's pretty interesting Paul, but kind of over the top for my purposes right now. I'll keep it on file for future reference. I think I can work with what I got for now.

    Thanks for the assist.

    Paul

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem Paul.
    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. Date/Time Field
    By donnan33 in forum Programming
    Replies: 2
    Last Post: 01-19-2012, 04:03 PM
  2. date/time field calculations
    By donnan33 in forum Queries
    Replies: 4
    Last Post: 01-13-2012, 11:58 AM
  3. Getting Just the Date part of Date/Time field
    By GaryElwood in forum Reports
    Replies: 7
    Last Post: 09-28-2011, 09:58 AM
  4. Date/Time Field Query...
    By Coffee in forum Queries
    Replies: 5
    Last Post: 07-05-2011, 11:27 PM
  5. date/time field
    By James890 in forum Database Design
    Replies: 1
    Last Post: 04-18-2007, 07:51 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