Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with validation

Status
Not open for further replies.

tigerlilly

Technical User
Mar 30, 2004
7
US
I need help with the following problem. I am trying to validate my fields when I click the command button I do not get an error message. My code is attached. Thank you!!

Private Sub cmdexit_Click()
Unload frminvestment
End Sub

Private Sub cmdFV_Click()
If Len(txtIR.Text) > 0 Then
If IsNumeric(txtIR.Text) = True Then

If Val(txtIR.Text) >= 1 _

And Val(txtIR.Text) <= 50 Then

fdblIR = CDbl(txtIR.Text)

Else

MsgBox &quot;you must enter a interest between 1 and 50&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtIR.SelStart = 0

txtIR.SetFocus

End If

End If
End If
End If

If Len(txtyears.Text) > 0 Then
If IsNumeric(txtyears.Text) = True Then

If Val(txtyears.Text) >= 1 And _

Val(txtyears.Text) <= 99 Then

fintyears = CInt(txtyears.Text)

Else

MsgBox &quot;you must enter years between 1 and 99&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtyears.SelStart = 0

txtyears.SetFocus

End If

End If
End If
End If

If Len(txtPV.Text) > 0 Then
If IsNumeric(txtPV.Text) = True Then

fcurPV = CCur(txtPV.Text)

Else

MsgBox &quot;you must enter a number for present value&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtPV.SelStart = 0

txtPV.SetFocus

End If

End If
End If

If txtFV = &quot;&quot; Then

fblnErrFlg = False

fcurFV = fcurPV * (1 + fdblIR * 0.01) ^ (fintyears)

txtFV.Text = Format(fcurFV, &quot;currency&quot;)
Else

MsgBox &quot;you must leave future value blank&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtFV.SelStart = 0

txtFV.SetFocus

End If
End If

End Sub

Private Sub cmdpayment_Click()
If Len(txtLA.Text) > 0 Then
If IsNumeric(txtLA.Text) = True Then

fcurLA = CCur(txtLA.Text)
Else

MsgBox &quot;You must enter a number for loan amount&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtLA.SelStart = 0

txtLA.SetFocus

End If
End If

If Len(txtLAIR.Text) > 0 Then
If IsNumeric(txtLAIR.Text) = True Then

If Val(txtLAIR.Text) >= 1 And _

Val(txtLAIR.Text) <= 50 Then

fdblLAIR = Val(txtLAIR.Text * 0.01)

Else

MsgBox &quot;YOu must enter a number for interest between 1 and 50&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtLAIR.SelStart = 0

txtLAIR.SetFocus

End If

End If
End If
End If

If Len(txtmth.Text) > 0 Then
If IsNumeric(txtmth.Text) = True Then

If Val(txtmth.Text) >= 12 And _

Val(txtmth.Text) <= 1000 Then

fintmth = CInt(txtmth.Text)

Else

MsgBox &quot;You must enter a number of months between 12 and 1000&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtmth.SelStart = 0

txtmth.SetFocus

End If

End If
End If
End If

If Len(txtmthpayment.Text) > 0 Then
If fblnErrFlg = False Then

fcurmthpayment = (fcurLA * fdblLAIR) / (1 - (1 + fdblLAIR)) ^ (-fintmth)

txtmthpayment.Text = Format(fcurmthpayment, &quot;currency&quot;)
Else

MsgBox &quot;you must leave this blank&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtmthpayment.SelStart = 0

txtmthpayment.SetFocus

End If
End If
End If
End If

End Sub

Private Sub cmdPV_Click()
If Len(txtIR.Text) > 0 Then
If IsNumeric(txtIR.Text) = True Then

If Val(txtIR) > 1 And _

Val(txtIR.Text) < 50 Then

fdblIR = CDbl(txtIR)

Else

MsgBox &quot;Interest is a required field&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtIR.SelStart = 0

txtIR.SetFocus

End If

Exit Sub

End If
End If
End If

If Len(txtyears.Text) > 0 Then

If IsNumeric(txtyears.Text) = True Then

If Val(txtyears.Text) >= 1 And _

Val(txtyears.Text) <= 99 Then

fintyears = CInt(txtyears.Text)

Else

MsgBox &quot;You must enter a number for years between 1 and 99&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtyears.SelStart = 0

txtyears.SetFocus

End If

End If

End If
End If

If Len(txtFV.Text) > 0 Then

If IsNumeric(txtFV.Text) = True Then

fcurFV = CCur(txtFV.Text)

Else

MsgBox &quot;You must enter a number for Future Value&quot;

If fblnErrFlg = False Then

fblnErrFlg = True

txtFV.SelStart = 0

txtFV.SetFocus

End If

End If
End If

If txtPV.Text = &quot;&quot; Then
fblnErrFlg = False
fcurPV = fcurFV / (1 + fdblIR * 0.01) ^ (fintyears)
txtPV.Text = Format(fcurPV, &quot;currency&quot;)
Else
MsgBox &quot;You must leave present value blank&quot;
fblnErrFlg = True
txtPV.SetFocus
End If
End Sub


 
Hi Tigerlilly,

use this pattern for validating each of your TextBoxes

Private Sub cmdFV_Click()
If (IsNumeric(txtIR.Text)) = True Then
If Val(txtIR.Text) >= 1 And Val(txtIR.Text) <= 50 Then
fdblIR = CDbl(txtIR.Text)
Else
MsgBox &quot;you must enter a interest between 1 and 50&quot;
txtIR.Text = &quot;&quot;
txtIR.SetFocus
Exit Sub
End If
Else
MsgBox &quot;Sorry, Invalid Data Entered&quot;
txtIR.Text = &quot;&quot;
txtIR.SetFocus
Exit Sub
End If

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top