on click will enter current time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm atempting to make what i thought would be a simple database used for a
help desk call log. From my switchboard i click "start a call" which brings
up my call log in a form view. When i do this i have it automaticly entering
the time and date. I have a buton on that form that once the required
information is filled out you click that closed that call, returning you to
the switch board. Well i want the the end time for the call to be recorded as
well. i have tried for hours to come up with a way. any ideas? PLEASE!
 
You'll need to place the code in one of the form events. I'd recommend
either Form_BeforeInsert or Form_AfterInsert.

Private Sub Form_BeforeInsert(Cancel As Integer)
EndTime = Now()
End Sub
 
Jeremy Corson said:
I'm atempting to make what i thought would be a simple database used
for a help desk call log. From my switchboard i click "start a call"
which brings up my call log in a form view. When i do this i have it
automaticly entering the time and date. I have a buton on that form
that once the required information is filled out you click that
closed that call, returning you to the switch board. Well i want the
the end time for the call to be recorded as well. i have tried for
hours to come up with a way. any ideas? PLEASE!

Presumably the call log information is in a record that is updated when
you click the "close call" button. If the code behind the button just
closes the form, the record will still be saved automatically by Access,
assuming this is a bound form. Therefore you could use the form's
BeforeUpdate event to set the CallEnded field (whatever you have called
it). The code for the event might look something like this:

'----- start of example code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.CallEnded) Then
Me.CallEnded = Now()
End If

End Sub
'----- end of code -----

Or, if there's a chance the form's record might be saved before you
intend for the call to end, you could just add a line to the event
procedure for the "End Call" button, to set the field value before
closing the form; e.g.,

'----- start of example code #2 -----
Private Sub cmdEndCall_Click()

Me.CallEnded = Now()

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
'----- end of code -----
 
Wow, thanks for your timly anwser! Can i just coppy and paste that somewhere?
is so where. Or could you IM me on MSN using this e-mail address and give me
a quick hand?
 
If you are clicking a button to indicate the call is complete, put it in a
text box bound to the end time field in the record in the Click event of the
button. For safety's sake, I would check to ensure it has been done in the
form Before Update event.

Click Event:

Me.txtCloseTime = Now()

Form Before Update:

If IsNull(Me.txtCloseTime) Then
MsgBox "No Close Time Entered"
Cancel = True
Me.cmdCloseButton.SetFocus
End If
 
Thanks dirk! I'm to new to this. I see that you have MSN messenger. Would you
mind just logging on?
 
Jeremy,

Most of us would prefer to keep the answers in the newsgroup, as it
tends to help other people as well.


On your form, in design view, bring up the properties window. Click on
the Events Tab. Find the one that is Before Insert. Using the drop
down box, select [Event Procedure]. Now, click the button on the side
with the three dots. That will take you to the code window. You
should see:



Private Sub Form_BeforeInsert(Cancel As Integer)


End Sub

Now, copy/paste either mine or Dirk's code. Neither one of us knows
for sure what the control is named that is the end time field.


Private Sub Form_BeforeInsert(Cancel As Integer)
[YOUR CONTROL NAME]= Now()
End Sub


Post back to the newsgroup if you have any other questions.


Chris Nebinger
 
You'll need to place the code in one of the form events. I'd
recommend either Form_BeforeInsert or Form_AfterInsert.

Private Sub Form_BeforeInsert(Cancel As Integer)
EndTime = Now()
End Sub

Chris, AfterInsert is not going to work, because at that point the
record has already been added. I have doubts about BeforeInsert,
because that will fire when the user first starts entering call data in
the new record, which may be before the call has actually ended. I
don't know all of the circumstances, though, so it's conceivable it
could work.
 
Back
Top