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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Dale FyeOwner, Developing Solutions LLCCommented:
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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pdvsaProject financeAuthor Commented:
thank you.  It was an education and I hopefully will retain it.  

:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.