By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Error message displayed on form depending on calculated value

P: 10
On my form I have a calculated value text box which is the sum of 5 text boxes. I have three error messages which I want to appear "high risk" "low risk" and "medium risk" depending on the value in the calculated text box. I have these error messages as labels on the form and when the form loads they are made not visible.

I want the messages to appear as the "calculate" button I have is clicked. Currently I only the last error message in the code appears when the button is clicked and the value is within the range specified. I feel like its something simple that I am missing but cant figure it out.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command43_Click()
  3.     txtcalculate.Value = CDbl(Nz([txt1], 0)) + CDbl(Nz([txt2], 0)) + CDbl(Nz([txt3], 0)) + CDbl(Nz([txt4], 0)) + CDbl(Nz([txt5], 0))
  6.     If txtscalculate.Value <= 16 Then
  7.             Me.lbllow.Visible = True
  8.      End If
  11.     If txtcalculate.Value >= 34 Then
  12.         Me.lblhigh.Visible = True
  13.     End If
  16.     If txtcalculate.Value = 17 - 33 Then
  17.         Me.lblmedium.Visible = True
  18.     End If
  21. End Sub
Mar 12 '14 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,240
You should begin with:
Expand|Select|Wrap|Line Numbers
  1. Me.lblmedium.Visible = false
  2. Me.lblhigh.Visible=false
  3. Me.lbllow.Visible=false
otherwise each subsequent button click could result in more than one error message being displayed.

This line
Expand|Select|Wrap|Line Numbers
  1. If txtcalculate.Value = 17 - 33 Then
is an obvious error. Probably you meant
Expand|Select|Wrap|Line Numbers
  1. If txtcalculate.Value >= 17 and  txtcalculate.Value <=33 Then
Are the 3 messages physically positioned separately? If they are on top of each other you might not see if more than one was lit up.

Mar 12 '14 #2

P: 10
Hi Jim!

Thanks so much for that! I am new to VB so didnt think the last piece of code was right but thanks for showing me how to do it! It now works like a treat!
Mar 13 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.