Results 1 to 6 of 6

Thread: Calculations

  1. #1
    Join Date
    Sep 2004
    Posts
    11

    Unanswered: Calculations

    I have used the DateDiff function to do some calculations on a time form. I want to get the calculated fields to show in my query and i am having a problem getting them formatted properly. I want to bring the calculated field from the form to my query, but instead of 1hr i get 0.04777... can someone help

  2. #2
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    could you type a bit your code here? I have no idea what the problem is.
    ghozy.

  3. #3
    Join Date
    Sep 2004
    Posts
    11
    here is the vb code for my pm calculation. I use this to get an elapsed time in an AM and PM form. i want to bring the elapsed time into my query. it may be better to send my MDB file but i am an Advanced Access newbe as well as a forum newbe and cannot send through the forum

    Option Compare Database

    Private Sub Command12_Click()
    On Error GoTo Err_Command12_Click


    Time_In_Afternoon.SetFocus

    Time_In_Afternoon.Text = Conversation.Str(DateTime.Now)

    Exit_Command12_Click:
    Exit Sub

    Err_Command12_Click:
    MsgBox Err.Description
    Resume Exit_Command12_Click

    End Sub
    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click


    Time_Out_Afternoon.SetFocus

    Time_Out_Afternoon.Text = Conversion.Str(DateTime.Now)

    Dim timein As String
    Dim timeout As String
    timeout = Time_Out_Afternoon.Text
    Time_In_Afternoon.SetFocus
    timein = Time_In_Afternoon.Text

    Elapsed_PM.SetFocus
    Dim diff As Double
    diff = DateTime.DateDiff("n", timein, timeout) / 60
    Elapsed.Text = Conversion.Str(diff)

    Exit_Command13_Click:


    Exit Sub

    Err_Command13_Click:
    MsgBox Err.Description
    Resume Exit_Command13_Click

    End Sub

    Private Sub Check_In_Click()

    Time_In_Afternoon.SetFocus

    Time_In_Afternoon.Text = DateTime.Now

    End Sub

    Private Sub Check_Out_Click()

    Time_Out_Afternoon.SetFocus

    Time_Out_Afternoon.Text = DateTime.Now

    Dim timein As String
    Dim timeout As String
    timeout = Time_Out_Afternoon.Text
    Time_In_Afternoon.SetFocus
    timein = Time_In_Afternoon.Text

    Elapsed_PM.SetFocus
    Dim diff As Double
    diff = DateTime.DateDiff("n", timein, timeout) / 60
    Elapsed_PM.Text = diff

    End Sub

    Private Sub Time_In_Afternoon_Click()
    End Sub

  4. #4
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    you might want to try "h" instead of "n" if you want get the hour difference.
    DateTime.DateDiff("h", timein, timeout)

    also in your code you write Conversation.str somewhere, which should be conversion.str.
    ghozy.

  5. #5
    Join Date
    Sep 2004
    Posts
    11
    Thanks ghozy i found my spelling error and changed the code but to no solution. the code calculates more accurate but i still cannot get the elapsed time in my query. ill keep working, any other pointers would be great

  6. #6
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    Code:
    Elapsed_PM.SetFocus
    Dim diff As Date
    diff = DateDiff("h", cdate(timein), cdate(timeout) )
    Elapsed_PM= diff
    this code should find hour difference between timein and timeout.
    ghozy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •