Using AfterUpdate events of two controls to update Date/Time record changed field

JeffBarker

Registered User.
Local time
Today, 12:31
Joined
Dec 7, 2010
Messages
130
Hi guys.

I'm having some problems with this - clearly a bit of a basic one so apologies in advance.

I'm currently in the process of creating a form to be used in an upcoming calling campaign, and I'm trying to get 1x combo box and 1x text box to update the Date/Time field that shows when the current record was changed.

What I need the controls to do is enter in the "Now" statement every time a new option is selected from the combo box, or some new text is entered in the text box - and likewise, if the field is cleared then the Date/Time field should also be updated.

I have the following code for both controls:

Code:
    If Me.cboStatus.Value <> Me.cboStatus.OldValue Then
        Me.LastCall = Now
    ElseIf Nz(cboStatus, vbNullString) = vbNullString Then
        Me.LastCall = Now
    End If

and

Code:
    If Me.txtOpNotes.Value <> Me.txtOpNotes.OldValue Then
        Me.LastCall = Now
    ElseIf Nz(txtOpNotes, vbNullString) = vbNullString Then
        Me.LastCall = Now
    End If

but I can only get the Date/Time field to update if using one of the above statments on a control - so either the *.value <> *.oldvalue, or Nz statements on the AfterUpdate event, but not together or as both statements entered into the AfterUpdate event.

Frustration!! Any suggestions on how to proceed with this would be excellent - thanks!

Jeff.
 
No point in testing anything, i.e. get rid of the IF statement. Just put the Now() code line in the After Update event.
 
Wow...that was super simple...classic case of over-complicating the matter...

Thanks vbaInet - that worked perfectly!

:)
 
Hey, vbaInet - just out of interest, not sure what I've done, but this now only updates when moving to the next record on the form...
 
Can I see the entire After Update event of the control?
 
So when you update the combo box the time doesn't change?

Change the textbox name from LastCall to txtLastCall and use this in your code:
Code:
Private Sub cboStatus_AfterUpdate()
    Me.[COLOR=Blue][B]txt[/B][/COLOR]LastCall = Now
End Sub
Leave the field name as it is.
 
So when you update the combo box the time doesn't change?

No, not automatically - you have to browse to the next record and then back again in order for it to change.

Change the textbox name from LastCall to txtLastCall and use this in your code:
Code:
Private Sub cboStatus_AfterUpdate()
    Me.[COLOR=blue][B]txt[/B][/COLOR]LastCall = Now
End Sub
Leave the field name as it is.

Do you know what, you've exactly hit the nail on the head - after I designed the rest of the form I tidied up after myself by renaming all the txt and cbo fields...and totally forgot to amend the code!!

D'oh!

Thanks for your time there, vbaInet! :)
 

Users who are viewing this thread

Back
Top Bottom