• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

Help with blank field in record

Hi,

I'm trying to write a code that checks for the field TDate in a record, if the TDate field is empty or null, then assigned the current date to the TDate, if date already exist, just display the date. The problem is if the date is empty it does not assign the date, it will just display "Date is         " What do I need to check for to make it assign a date?


Private Sub TDate_click()
    If Me.TDate = Null Then
        Me.TDate = Date
    Else
        MsgBox "Date is " & Me.TDate & ""
    End If
End Sub

I've tried also using

If Me.TDate = "" Then

0
Fr3aK
Asked:
Fr3aK
1 Solution
 
hans_vdCommented:
Why don't you try this:

'IsDate checks whether your variable holds an valuable Date
Private Sub TDate_click()
   If IsDate(Me.TDate) Then
       Me.TDate = Date
   Else
       MsgBox "Date is " & Me.TDate & ""
   End If
End Sub


or this:

'You can use 'Or' in an If statement to perform two checks
'Use the function IsNull instead of '... = Null'
Private Sub TDate_click()
   If IsNull(Me.TDate) Or Me.TDate = "" Then
       Me.TDate = Date
   Else
       MsgBox "Date is " & Me.TDate & ""
   End If
End Sub
0
 
MarkKoroCommented:
If you have your fields defined as dates and they are not null than this code should work...

Private Sub TDate_click()
   dim ChkDate as date
   If Me.TDate = ChkDate Then
       Me.TDate = Date
   Else
       MsgBox "Date is " & Me.TDate & ""
   End If
End Sub

 
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now