Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Update to today's date

Experts, the below code is my code and I know it is wrong.  
I think you can see what I am trying to do.
I need to update txtDateCompleted to today's date.

thx

Private Sub txtCompleted_AfterUpdate()

    If Me.txtDateCompleted = "" Then
        Me.txtDateCompleted = Date
    Else
   
    End If
   
End Sub
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Have you tried date()
Private Sub txtCompleted_AfterUpdate()

    If Me.txtDateCompleted.Value = "" Then
        Me.txtDateCompleted.Value = Date()
    Else
   
    End If
   
End Sub
Avatar of pdvsa

ASKER

Lee that's not it either.  

I probably named txtCompleted incorrectly (I just noticed this actually).  It is a value list combo box with value Yes or No.  

maybe that changes something?
No points please!

How about:

1.  Changing the name of the combo box to cboCompleted

2.  Changing the AfterUpdate event to:

Private sub cboCompleted_AfterUpdate()

    Me.txtDateCompleted = iif(NZ(me.cboCompleted, "") = "Yes", Date(), NULL)

End Sub

Open in new window

This will make the DateCompleted NULL if cboCompleted is anything other than "Yes" and todays date if it is "Yes"
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdvsa

ASKER

thank you.  It was an education and I hopefully will retain it.  

:)