Data Entry Validation

  • Thread starter Thread starter Bonnie
  • Start date Start date
B

Bonnie

Hi, any help appreciated. I am trying to validate data
that is keyed in a form. I have a form that opens first
to collect batch information that then opens the data
entry form. Here's the code I have been working with:

Private Sub Text96_BeforeUpdate(Cancel As Integer)
If IsNull(Forms![Liens]![Text96]) And Forms![batch
info]![Text7] = "JS" Then
If CStr(Forms![batch info]![Text7]) = "JS" Or CStr
(Forms![batch info]![Text7]) = "PL" Then
DoCmd.Beep
MsgBox "Requires a release date!",
vbExclamation, "Release Date"
Cancel = True
End If
End If
If CStr(Forms![batch info]![Text7]) <> "JS" Or
Not IsNull(Forms![Liens]![Text96]) And CStr(Forms![batch
info]![Text7]) <> "PL" Then
DoCmd.Beep
MsgBox "NO release date required!? Hit
Escape.", vbExclamation, "Release Date"
Cancel = True
End If
End If
End Sub

I've tried the conditions in the immediate window and get
the expected answer (True or False) but they don't work
from the form. Any ideas? The conditions are too
complicated to put into the validation property. I've
tried all kinds of syntax and constructs on the IF THEN
ELSE.

Thanks.
 
Bonnie,
Hi, any help appreciated. I am trying to validate data
that is keyed in a form. I have a form that opens first
to collect batch information that then opens the data
entry form. Here's the code I have been working with:

Private Sub Text96_BeforeUpdate(Cancel As Integer)
If IsNull(Forms![Liens]![Text96]) And Forms![batch
info]![Text7] = "JS" Then
If CStr(Forms![batch info]![Text7]) = "JS" Or CStr
(Forms![batch info]![Text7]) = "PL" Then

In the first If you put the condition Text7 = "JS". You only get to
the inner IF, if this is true. Therefore, if Text7 is "PL", the inner
If with MsgBox and Cancel won't be executed.
If CStr(Forms![batch info]![Text7]) <> "JS" Or
Not IsNull(Forms![Liens]![Text96]) And CStr(Forms![batch
info]![Text7]) <> "PL" Then

Let's suppose, Text7 has the value "JS". The very first condition is
false, but the second one:
Not IsNull(Forms![Liens]![Text96]) _
And CStr(Forms![batch info]![Text7]) <> "PL"

is true, so you'll get the message and Cancel set to true. But this
contradicts the logic from the first big If, where you would require a
date when Text7 is "JS".

Couple of advices to make the code more readable: If this code runs in
the [batch info] form, then you can use Me instead of Forms![batch
info].
You don't need the CStr function, the text box Text7 obviously will
contain only strings.
Please change the names of the controls as soon as they're created. Or
would you know what Text7 represents in say, 1 year?
What is the form Liens?
I've tried the conditions in the immediate window and get
the expected answer (True or False) but they don't work
from the form. Any ideas? The conditions are too
complicated to put into the validation property. I've
tried all kinds of syntax and constructs on the IF THEN
ELSE.

Please try to explain the conditions in your own words without code.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Back
Top