How to transfer numbers in an unbound text box to a number field in a table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • M Feightner

    How to transfer numbers in an unbound text box to a number field in a table?

    I have stopwatch function on my form that works fine. I used code from http://support.microso ft.com/kb/233275.
    My problem now is taking the value from the unbound text box and entering into my table for record time.

    If I leave the field in the table as text will transfer fine but then I can not use the value in mathematical functions, which I need.

    Can someone help me please?
  • gnawoncents
    New Member
    • May 2010
    • 214

    #2
    My suggestion would be to store the numeric value as milliseconds in your table. That way you could perform any mathematical functions required. If you need both the text and numeric, then simply store both. You can pull the ElapsedMilliSec value from the events by adding a few lines to two of your events as seen below. Note: I added a textbox (txtTime) to my form in this case.

    Code:
    Private Sub btnReset_Click()
    
       TotalElapsedMilliSec = 0
       Me!ElapsedTime = "00:00:00:00"
       'Add this line to reset the numeric value ( in milliseconds)
       Me!txtTime = 0
    
    End Sub
    
    Private Sub Form_Timer()
    
       Dim Hours As String
       Dim Minutes As String
       Dim Seconds As String
       Dim MilliSec As String
       Dim Msg As String
       Dim ElapsedMilliSec As Long
    
       ElapsedMilliSec = (GetTickCount() - StartTickCount) + _
          TotalElapsedMilliSec
          
    'Add this line to get the numeric value ( in milliseconds)
    Me.txtTime = ElapsedMilliSec
    
       Hours = Format((ElapsedMilliSec \ 3600000), "00")
       Minutes = Format((ElapsedMilliSec \ 60000) Mod 60, "00")
       Seconds = Format((ElapsedMilliSec \ 1000) Mod 60, "00")
       MilliSec = Format((ElapsedMilliSec Mod 1000) \ 10, "00")
    
       Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" _
          & MilliSec
    
    End Sub

    Comment

    • M Feightner

      #3
      Worked Great

      Thank you very much. It worked great. I was just over thinking it.
      For anyone else who needs this, I had to convert the milliseconds to seconds and use the DateAdd function to my time stamp to get a stop date and time.

      Comment

      Working...