Validating blank entry in text boxes

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
 
R

Ron Weiner

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
 
G

Gijs Beukenoot

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
 

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