By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,649 Members | 1,572 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,649 IT Pros & Developers. It's quick & easy.

Passing a date value

P: n/a
I am fairly novice at VB and access in particular and I am having
problems trying store a date into database field.

This is the scenario I am faced with.

I want to when click on a pause button and store the current date time
in a pause time field then when it is then unclicked it is to add the
time that elapsed to a total pause time field and the reset the pause
time back to Null.

If anyone knows as to how to do this it will be much appreciated here
is the code that I am using at the moment.

Private Sub cmdPause_Click()
If cmdPause = -1 Then
'Record Current Time
dteStartPause = Now()
UpdatePunchClock (punchClock_Paused)

Else
'Get current time - recorded time
PauseTime = Nz(PauseTime, 0) + CalcHours(dteStartPause, Now())
RecalcHours

UpdatePunchClock (punchClock_Started)
End If

End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Flipmode wrote:
I am fairly novice at VB and access in particular and I am having
problems trying store a date into database field.

This is the scenario I am faced with.

I want to when click on a pause button and store the current date time
in a pause time field then when it is then unclicked it is to add the
time that elapsed to a total pause time field and the reset the pause
time back to Null.

If anyone knows as to how to do this it will be much appreciated here
is the code that I am using at the moment.

Private Sub cmdPause_Click()
If cmdPause = -1 Then
'Record Current Time
dteStartPause = Now()
UpdatePunchClock (punchClock_Paused)

Else
'Get current time - recorded time
PauseTime = Nz(PauseTime, 0) + CalcHours(dteStartPause, Now())
RecalcHours

UpdatePunchClock (punchClock_Started)
End If

End Sub


This may help. You can test this out by following what I did.

I created a new form. I added 2 text boxes
Name = PauseTime DefaultValue = 0
Name = HoldTime DefaultValue = 0

I dropped a Toggle button onto the form. It's name is Toggle1

I dropped a Command button onto the form. It's name is CommandElapsed.

Now copy the below code, from Option Compare to the last End Sub into
the code window of the form.

Option Compare Database
Option Explicit
Private Sub Toggle1_Click()
If Me.Toggle1 = -1 Then
'toggle pressed in
Me.HoldTime = Now()
Else
'toggle released

'store the time difference in seconds
Me.PauseTime = Me.PauseTime + DateDiff("s", Me.HoldTime, Now())

'reset the holder. You really don't need to do this as it gets
'overwritten each time the toggle is pressed in.
Me.HoldTime = 0
End If
End Sub

Private Sub CommandElapsed_Click()

Dim h As Long, m As Long, s As Long

h = Int(Me.PauseTime / 3600) 'hours
m = Int((Me.PauseTime - (h * 3600)) / 60) 'minutes
s = Me.PauseTime - ((h * 3600) + (m * 60)) 'seconds
MsgBox Format(h, "00") & ":" & Format(m, "00") & _
":" & Format(s, "00")

End Sub

When the Toggle1 is pressed in, it stores the current time to HoldTime.
When it is released, it adds the difference in time toggled to
PauseTime. It also resets the HoldTime to 0

When CommandElapsed is pressed, it displays the hours, minutes, and seconds

I recommend that the time in PauseTime to be stored in seconds. You can
then determine the number of hours, minutes, and seconds...as the
routine does in CommandElapsed_Click.
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.