Trying to debug a problem

gbanks

Registered User.
Local time
Today, 15:46
Joined
Feb 9, 2000
Messages
161
Using code on a form to look for a null value for a field on my form. For soem reason this isn't working. I'm checking for a null value in the field on the form. Even if the ClosedDate field is null it still shows the Not null message box. Am I doing something wrong? Thanks

Private Sub Command102_Click()
If Me.ClosedDate = Null Then
MsgBox "Null"
Else
MsgBox "Not Null"
End If

End Sub
 
gbanks said:
Using code on a form to look for a null value for a field on my form. For soem reason this isn't working. I'm checking for a null value in the field on the form. Even if the ClosedDate field is null it still shows the Not null message box. Am I doing something wrong? Thanks

Private Sub Command102_Click()
If Me.ClosedDate = Null Then
MsgBox "Null"
Else
MsgBox "Not Null"
End If

End Sub

Try using the ISNull() function to determin if the ClosedDate field is null or not.

To look up info on that, use the F1 help feature and look that up in the VBA window in access.
 
IsNull Function Example

The following example uses the IsNull function to determine whether the value of a control is Null. If it is, a message prompts the user to enter data. If the value is not Null, a message displays the value of the control.

Sub ControlValue(ctlText As Control)
Dim strMsg As String

' Check that control is text box.
If ctlText.ControlType = acTextBox Then
' If value of control is Null, prompt for data.
If IsNull(ctlText.Value) Then
strMsg = "No data in the field '" & ctlText.Name _
& "'." & vbCrLf & "Please enter data for " _
& "this field now."
If MsgBox(strMsg, vbQuestion) = vbOK Then
Exit Sub
End If
' If value is not Null, display value.
Else
MsgBox (ctlText.Value)
End If
End If
End Sub

Above is the ISNull function example in Access.

HTH
Selena
 

Users who are viewing this thread

Back
Top Bottom