Form Closing after data check failure

R

rmcompute

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
 
S

SteveM

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
 
S

SteveM

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

Steve
 
D

Douglas J. Steele

"" 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.)
 
S

SteveM

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
 
R

rmcompute

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 ?
 

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