tigerlilly
Technical User
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 "you must enter a interest between 1 and 50"
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 "you must enter years between 1 and 99"
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 "you must enter a number for present value"
If fblnErrFlg = False Then
fblnErrFlg = True
txtPV.SelStart = 0
txtPV.SetFocus
End If
End If
End If
If txtFV = "" Then
fblnErrFlg = False
fcurFV = fcurPV * (1 + fdblIR * 0.01) ^ (fintyears)
txtFV.Text = Format(fcurFV, "currency"
Else
MsgBox "you must leave future value blank"
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 "You must enter a number for loan amount"
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 "YOu must enter a number for interest between 1 and 50"
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 "You must enter a number of months between 12 and 1000"
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, "currency"
Else
MsgBox "you must leave this blank"
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 "Interest is a required field"
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 "You must enter a number for years between 1 and 99"
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 "You must enter a number for Future Value"
If fblnErrFlg = False Then
fblnErrFlg = True
txtFV.SelStart = 0
txtFV.SetFocus
End If
End If
End If
If txtPV.Text = "" Then
fblnErrFlg = False
fcurPV = fcurFV / (1 + fdblIR * 0.01) ^ (fintyears)
txtPV.Text = Format(fcurPV, "currency"
Else
MsgBox "You must leave present value blank"
fblnErrFlg = True
txtPV.SetFocus
End If
End Sub
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 "you must enter a interest between 1 and 50"
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 "you must enter years between 1 and 99"
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 "you must enter a number for present value"
If fblnErrFlg = False Then
fblnErrFlg = True
txtPV.SelStart = 0
txtPV.SetFocus
End If
End If
End If
If txtFV = "" Then
fblnErrFlg = False
fcurFV = fcurPV * (1 + fdblIR * 0.01) ^ (fintyears)
txtFV.Text = Format(fcurFV, "currency"
Else
MsgBox "you must leave future value blank"
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 "You must enter a number for loan amount"
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 "YOu must enter a number for interest between 1 and 50"
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 "You must enter a number of months between 12 and 1000"
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, "currency"
Else
MsgBox "you must leave this blank"
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 "Interest is a required field"
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 "You must enter a number for years between 1 and 99"
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 "You must enter a number for Future Value"
If fblnErrFlg = False Then
fblnErrFlg = True
txtFV.SelStart = 0
txtFV.SetFocus
End If
End If
End If
If txtPV.Text = "" Then
fblnErrFlg = False
fcurPV = fcurFV / (1 + fdblIR * 0.01) ^ (fintyears)
txtPV.Text = Format(fcurPV, "currency"
Else
MsgBox "You must leave present value blank"
fblnErrFlg = True
txtPV.SetFocus
End If
End Sub