Form Closing after data check failure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have coded error checking in the Before Update event, however, when the
user enters the wrong information, the error message displays correctly, but
the form closes. I have played with the Default View and Cycle properties,
but it still closes.
Any ideas ?


I have coded the following in the Before Update Event

If IsNull(Me.RptDir) Or LTrim(RTrim(Me.RptDir)) = "" Then
Me.RptDir.SetFocus
Cancel = MsgBox("You must enter a Report Directory.", vbCritical, "Data
Validation Failure")
End If

The relevent properties are currently set as follows:
Default View: Continuous Forms
Cycle: All Records
 
Try this:

If IsNull(Me.RptDir) Or LTrim(RTrim(Me.RptDir)) = "" Then
MsgBox "You must enter a Report Directory.", vbCritical, "Data Validation
Failure"
Cancel = True
End If

Steve
 
Wouldn't Nz() return "" (zero length string) if Me.RptDir were Null in your
example, therefore never actually returning vbNullString?

Steve
 
"" and vbNullString are the same thing.

From the Immediate window:

?"" = vbNullString
True

You may be confusing vbNullString with Null.

One small improvement on Dave's small improvment:

If Trim(Nz(Me.RptDir,vbNullString)) = vbNullString Then

(it's more efficient to use an already declared constant, such as
vbNullString, than to repeat the actual literal value.)
 
Ah! didn't know that!

I always use it like: If Nz(strVal,"") = "" Then... or If Nz(numVal,0) = 0
Then...
so I've never hit that before!

Steve
 
I've made the change and the error message still displays, but the form still
closes. Is there possibly some form property that needs to get set ?
 
Back
Top