Having trouble with "If date is blank, then..."

T

Tech Geek 1234

I have a form that has a "save" command button on the form for users to save
the record before printing/previewing. On this form I have a RLSDTE and a
RLSTME field. The date field is actually stored as a date rather than text
(the person who created the database created it as text and was able to have
the following code work). I changed it to store as date. I want a warning
msgbox to pop up if the date field is not filled in.

Previously, the If statement read: "If me.RLSDTE = "Enter Date" then..."
But now that it's a date field and not text, I can't have the default text be
"Enter Date". So I'm leaving it blank. But I can't figure out how to redo
my If statement to be "If me.RLSDTE Is Null" or "If me.RLSDTE = "", then pop
up the msg box reminding the user to enter the date. Code is below:

Private Sub Command111_Click() 'Command111 is Save button on form
'This will save the record, and check the Release date and time fields

Dim Response, style, msg, Title As String

If Me.RLSDTE = "Enter Date" Then
Response = MsgBox("Do not forget to enter a Release DATE", vbOKOnly +
vbInformation, "Reminder")
RLSDTE.BackColor = vbYellow
End If

If Me.RLSTM = "Enter Time" Then
Response = MsgBox("Do not forget to enter a Release Time", vbOKOnly +
vbInformation, "Reminder")
RLSTM.BackColor = vbYellow
Else
Me.Refresh
End If

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

End Sub


I feel like maybe I need to go back to VB 101 to get the right code. Can
you help?
 
O

Ofer Cohen

Try

Private Sub Command111_Click() 'Command111 is Save button on form
'This will save the record, and check the Release date and time fields

Dim Response, style, msg, Title As String

If Len(Me.RLSDTE & "") = 0 Then
Response = MsgBox("Do not forget to enter a Release DATE", vbOKOnly +
vbInformation, "Reminder")
RLSDTE.BackColor = vbYellow
Me.RLSDTE.SetFocus ' set the focus to the field
Exit Sub
End If

If Len(Me.RLSTM & "") = 0 Then
Response = MsgBox("Do not forget to enter a Release Time", vbOKOnly +
vbInformation, "Reminder")
RLSTM.BackColor = vbYellow
Me.RLSTM.SetFocus ' set the focus to the field
Exit Sub
End If

If Me.Dirty Then
Me.Dirty = False ' will save the record
End if
End Sub
 
E

e.mel.net

I'm sure everyone has banged their head up against this problem, NULL
<> ""
They are the difference between being "not set" and "set to nothing."

I used to get aroung this by using
str & "" = ""
....but...
int + 0 = 0
doesnt work

I've only recently found the Nz function - very cool

Nz(str) returns the string if it is set or "" if it is null
Nz(int) returns the number if it is set or 0 if it is null
Nz(str, "NULL") returns the string if it is set or the string "NULL" if
it is null - ver usefull when building an SQL string
 
T

Tim Ferguson

[email protected] wrote in @m79g2000cwm.googlegroups.com:
Nz(str, "NULL") returns the string if it is set or the string "NULL" if
it is null - ver usefull when building an SQL string

The quote marks are, of course, very significant:

Nz(aVariant, NULL)

is not generally very helpful!

All the best


Tim F
 
T

Tech Geek 1234

Thank you everyone! I used the "If IsNull(Me.RLSDTE) Then" and it worked
perfectly. I'm sure the others would work also. Thanks!
 
Top