If Null test

Foe

Registered User.
Local time
Today, 07:54
Joined
Aug 28, 2013
Messages
80
So, about 3 weeks ago, I decided to rebuild a database that my workplace uses. The original was built in '05 and has been stagnant since that time. I hadn't used Access since about 2002 and had never written code before. Needless to say, this was a big undertaking. Everything I've learned is all self taught over the last few weeks. Poke at it and see what happens type of approach.

Very frequently, I decide what I want to do and then turn to the interwebs to figure out how. 9 times out of 10, this forum is where I found intelligible answers. Which leads me to the first question I'm going to ask on my own instead of fishing for an existing answer for hours.

So without further adieu, I have this code snippet that isn't working as intended:

Code:
Private Sub txtDate_GotFocus()
    Me.txtDate = Now()
End Sub

Private Sub cmdCancel_Click()
    If Me.Dirty Then
        Me.Undo
    End If
    DoCmd.Close acForm, "frmCloseEmail"
End Sub

Private Sub cmdSubmit_Click()
    If Me.txtDate = Null Then
        Me.txtDate = Now()
    End If
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close acForm, "frmCloseEmail"
    Forms!frmGUI!listActiveEmails.Requery
End Sub

This is on a form that (I hope obviously) is intended to close out an email (aka:trouble ticket). When tabbing through fields, when I land in txtDate the =NOW() is working as intended. However, in an attempt to ensure nothing was ever submitted w/o a date/time entered, I created the If statement to put =NOW() into the txtDate field if it was empty upon clicking cmdSubmit. But it doesn't work. I don't get any errors, but nothing happens. Why not?

What I've included is the entire code for that form. I am not using any macros either (forcing myself to learn the equivalent vba). The txtDate control is not populating with any Default data, so by all accounts it should be Null unless it gets focus.

Advice is kindly appreciated. Thanks!
 
Last edited:
Re: Hope this is the correct place to ask

Try:
If isnull(Me.txtDate) Then
 
Re: Hope this is the correct place to ask

Try

If Not IsDate(Me.txtDate) Then

The Null test would be

If IsNull(Me.txtDate) Then
 
Re: Hope this is the correct place to ask

Holy smokes you guys are fast!

Love the IsDate test! Fantastic suggestion!

Problem solved.

So much syntax to learn...
 
Re: Hope this is the correct place to ask

We were happy to help, and welcome to the site by the way! In the future, a more descriptive thread title can help people searching for a solution later.
 
Re: Hope this is the correct place to ask

We were happy to help, and welcome to the site by the way! In the future, a more descriptive thread title can help people searching for a solution later.

I'm trying to figure out how to edit that at this very moment.

It's updating the title on the individual post, but not for the thread in general.
 

Users who are viewing this thread

Back
Top Bottom