Required Entry

  • Thread starter Rpt_Me4NotBeingSmart
  • Start date
R

Rpt_Me4NotBeingSmart

I used the code below as the eventprocedure for the form but I am not getting
an error message when VarianceCode = I and OtherNotes is blank/null. Did I
do something wrong here?



Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.VarianceCode, "") = "I" Then
If IsNull(Me.OtherNotes) Then
Me.OtherNotes.SetFocus
MsgBox "You must enter notes if the variance code is I", , "Cannot
update record"
Cancel = True
End If
End If
End Sub
 
D

Douglas J. Steele

Blank and Null are two different things.

See whether replacing

If IsNull(Me.OtherNotes) Then

with

If Len(Me.OtherNotes & vbNullString) = 0 Then

makes any difference.
 
D

Dirk Goldgar

Rpt_Me4NotBeingSmart said:
I used the code below as the eventprocedure for the form but I am not
getting
an error message when VarianceCode = I and OtherNotes is blank/null. Did
I
do something wrong here?



Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.VarianceCode, "") = "I" Then
If IsNull(Me.OtherNotes) Then
Me.OtherNotes.SetFocus
MsgBox "You must enter notes if the variance code is I", , "Cannot
update record"
Cancel = True
End If
End If
End Sub


Could it be that OtherNotes is a zero-length string ("") or even contains
blanks? That's unlikely unless you have such a value as the control/field's
DefaultValue, but you could check for it like this:

If Len(Trim(Me.OtherNotes & vbNullString)) = 0 Then

If that doesn't work, then set a breakpoint in the procedure and step
through the code to see what path it takes. While doing so, check the
values of the controls to see if they contain what you think.

It occurs to me that OtherNotes might also contain the new-line characters,
Chr(13 & Chr(10).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top