Validating blank entry in text boxes

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

Guest

Hi all,

I have a form that a user has to input values into. The form consists of
about 30 pairs of text boxes, in the following format

TxtA1 txtA2
TxtB1 txtB2
Etc.

Now, when the user enters something into txtA1, the value(an integer) must
be smaller than the value entered into txtA2. For example, txtA1 is “Age
minimum†and txtA2 is “Age maximumâ€

I have a validation function to check that the entered data makes sense, but
when I have a blank pair of text boxes, I get a “type incompatible†run-time
error.
I used the following code to check:

If Nz(CInt(Me.txtA1)) > Nz(CInt(Me.txtA2)) Then
MsgBox "Der Maximum in the range for Age Groups must be greater than the
minimum.", vbOKOnly + vbExclamation, "Error"
ValidateRanges = False
End If

What is wrong here? If I swap Nz and Cint, the same happens
(i.e. If CInt(Nz(Me.txtA1)) > CInt(Nz(Me.txtA2)) Then …)
Regards,
Jean
 
Try

If CInt(Nz(Me.txtA1, 0)) > CInt(Nz(Me.txtA2, 0)) Then .

You were missing the second parameter (Value When Null) of the Nz()
function.

Ron W
 
bavjean had uiteengezet :
Hi all,

I have a form that a user has to input values into. The form consists of
about 30 pairs of text boxes, in the following format

TxtA1 txtA2
TxtB1 txtB2
Etc.

Now, when the user enters something into txtA1, the value(an integer) must
be smaller than the value entered into txtA2. For example, txtA1 is ⤽Age
minimum� and txtA2 is ⤽Age maximum�

I have a validation function to check that the entered data makes sense, but
when I have a blank pair of text boxes, I get a ⤽type incompatible�
run-time error.
I used the following code to check:

If Nz(CInt(Me.txtA1)) > Nz(CInt(Me.txtA2)) Then
MsgBox "Der Maximum in the range for Age Groups must be greater than the
minimum.", vbOKOnly + vbExclamation, "Error"
ValidateRanges = False
End If

What is wrong here? If I swap Nz and Cint, the same happens
(i.e. If CInt(Nz(Me.txtA1)) > CInt(Nz(Me.txtA2)) Then ⤦)
Regards,
Jean

CInt is incompatible with null...
Try
if val(nz(me.txta1) > val(nz(me.txta2) then
 
Back
Top