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
pdvsaProject financeAsked:
Who is Participating?
 
PatHartmanCommented:
Dates are numeric data types so they could never = "" which is a Zero Length STRING.

So, if you are looking at a date/time data type you would do one of the following.
If Not IsDate(Me.txtDateCompleted) Then
         Me.txtDateCompleted = Date
End If

Open in new window

Or
If IsNull(Me.txtDateCompleted) Then
         Me.txtDateCompleted = Date
End If

Open in new window

Use whichever makes more sense to you.

However, if Me.txtCompleted is a string data type then you can't set it to a date.  Also having both a "flag" and a "date" is redundant.  You should only keep the "date" data field.  That way you can have the effect of a flag by checking for a valid date using the IsDate() function if all you want to know is IF something has been completed.
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Have you tried date()
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Private Sub txtCompleted_AfterUpdate()

    If Me.txtDateCompleted.Value = "" Then
        Me.txtDateCompleted.Value = Date()
    Else
   
    End If
   
End Sub
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
pdvsaProject financeAuthor Commented:
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?
0
 
Dale FyeCommented:
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"
0
 
pdvsaProject financeAuthor Commented:
thank you.  It was an education and I hopefully will retain it.  

:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.