Results 1 to 9 of 9
  1. #1
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95

    insert date and specific time into textbox

    I have a form for creating projects in a database. I originally set this up with 5 buttons for when the project is due to be at 1 hr, 2 hrs, etc. Now, they "management" want me change two of these for end of shift of on the current day and start of shift for the next day. This is the code I had before for the 6 hrs:

    Private Sub Command152_Click()
    Me.DueTime = RoundTime(Now() + 6 / 24, 1800)
    End Sub

    I'm not a database / programmer guy so I really could use some help or even point me to an article that would show how to do this.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am not sure what data type you have in your DueTime control. I will say this, you do not want to round your time. Check out this code. Place it in a click event to see how data types behave. Understand that Access sees a date as a double. Behind the scenes (when using Date Data Types), Access will display it as a date for you.

    Code:
    Dim date1 As Date
    Dim myDouble As Double
    date1 = Now()
    myDouble = date1
    MsgBox "Date Data Type: " & date1 & vbCr & "Double Data type: " & myDouble

  3. #3
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Thanks for the response.

    I get a message box showing

    Date Date Type:
    6/1/2015 10:12:58 AM
    Double Data type: 42156.4256712963

    The other code I added just as reference for what I had previously, I actually do need to round the time and these other buttons are doing what is needed.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This is how Access understands the Date field
    Double Data type: 42156.4256712963

    So, you do not want to goof around with a date value. You can use Text (inserting literal strings) and also use the many functions Microsoft offers to work with the Date data type.

    It seems you are using a custom User Defined Function. So without looking at the function, I can not understand what the overall objective is.

    Perhaps you can start again by explaining what you are trying to log. Break off a small piece and explain that. Are you trying to add hours to the current time?

  5. #5
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    This database is for my department that handles a couple hundred of word processing, graphical, or Excel type projects a day and the duetime is just a field that the person requesting the work needs to have that project completed and returned to them. I have a separate form that organizes these projects once the project is created; it will sort these projects by the duetime. Normally, the requestor just ask for the work in the next one or two hours. However, some people just say I need the work by the end of the business day, which means 5PM or by start of the next business day which means 9 am the next day. The department is open 7 days a week. The rounding is required on the first three buttons that I have for 1 hour, 2 hour, or 3 hours for duetime from now and this all works fine.

    All I'm trying to do is change the next couple of cmd button I have to not round the time but enter the end of business day or start of shift for the next day.

  6. #6
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    This is what I'm trying for end of shift or 5pm today. I'm pretty sure it's just an issue with how I

    Private Sub Command152_Click()
    Me.DueTime = Date And "5:00:00 PM"
    End Sub

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    OK, so you can use literal text and some casting to get the job done. Does this make sense to you here?

    Code:
    Dim strDate5PM As String
    Dim myDate As Date
    strDate5PM = Date & " 5:00 PM"
    myDate = strDate5PM
    MsgBox myDate

  8. #8
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Thank you so much. This is great.

    I've got both working now.

    Private Sub Command152_Click()
    Dim strDate5PM As String
    Dim myDate As Date
    strDate5PM = Date & " 5:00 PM"
    myDate = strDate5PM
    Me.DueTime = myDate
    End Sub


    AND

    Private Sub Command153_Click()
    Dim strDate5PM As String
    Dim myDate As Date
    strDate5PM = Date + 1 & " 9:00 AM"
    myDate = strDate5PM
    Me.DueTime = myDate
    End Sub

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Yup, and you should be able to pass your string straight to the control. The trick is to understand your data types. If your control is bound to a Date field, it should work just fine like this

    Code:
    Private Sub Command152_Click()
     Dim strDate5PM As String
     'Dim myDate As Date
     strDate5PM = Date & " 5:00 PM"
     Me.DueTime = strDate5PM
     'Me.DueTime = myDate
     End Sub

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

Similar Threads

  1. insert a specific date in report footer
    By Rasha in forum Access
    Replies: 3
    Last Post: 04-23-2014, 12:12 PM
  2. Get records after specific date and time
    By rooster in forum Queries
    Replies: 6
    Last Post: 09-15-2013, 11:32 PM
  3. Selecting from specific Date and Time range
    By LindaRuble in forum Programming
    Replies: 1
    Last Post: 05-15-2013, 07:37 AM
  4. Replies: 2
    Last Post: 02-02-2012, 06:06 AM
  5. Insert date and time into excel sheet.
    By alphaol in forum Forms
    Replies: 5
    Last Post: 11-23-2011, 03:09 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