I have text boxes and labels that show values, using formulas such as
the code below for Label7:
Private Sub TextBox2_Change()
Label7.Caption = Application.Text(CDbl(TextBox1.Value - TextBox2.Value)
/ (TextBox3.Value - 1), quot;# ??/16quot;)
End Sub
If I am in textbox2 and enter a value, it works fine, if I want to
change the value by pressing back space I get a error, because (I
assume, it becomes a zero error)
...is there a way to trap this error and still be able to stay in the
textbox?Private Sub TextBox2_Change()
Dim tmp
If TextBox1.Value = quot;quot; Or TextBox3.Value = quot;quot; Then
MsgBox quot;Incomplete dataquot;
Else
tmp = CDbl(TextBox1.Value)
If TextBox2.Text lt;gt; quot;quot; Then
tmp = tmp CDbl(TextBox2.Value)
End If
tmp = tmp / CDbl(TextBox3.Value - 1)
Label7.Caption = Application.Text(tmp, quot;# ??/16quot;)
End If
End Sub--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
quot;damorrisonquot; gt; wrote in message oups.com...
gt; I have text boxes and labels that show values, using formulas such as
gt; the code below for Label7:
gt;
gt; Private Sub TextBox2_Change()
gt; Label7.Caption = Application.Text(CDbl(TextBox1.Value - TextBox2.Value)
gt; / (TextBox3.Value - 1), quot;# ??/16quot;)
gt; End Sub
gt;
gt; If I am in textbox2 and enter a value, it works fine, if I want to
gt; change the value by pressing back space I get a error, because (I
gt; assume, it becomes a zero error)
gt;
gt; ..is there a way to trap this error and still be able to stay in the
gt; textbox?
gt;
I think I'd check to make sure everything was numeric and that textbox3.value
was different than 1 (no div/0 errors):
Option Explicit
Private Sub TextBox2_Change()
If IsNumeric(Me.TextBox1.Value) _
And IsNumeric(Me.TextBox2.Value) _
And IsNumeric(Me.TextBox3.Value) Then
If Me.TextBox3.Value lt;gt; 1 Then
Me.Label7.Caption _
= Format(CDbl(TextBox1.Value - TextBox2.Value) _
/ (TextBox3.Value - 1), quot;# ??/16quot;)
Else
Me.Label7.Caption = quot;quot;
End If
End If
End Sub
And Format worked ok for me instead of application.text--not all number formats
can be done this way, but this one was ok.
damorrison wrote:
gt;
gt; I have text boxes and labels that show values, using formulas such as
gt; the code below for Label7:
gt;
gt; Private Sub TextBox2_Change()
gt; Label7.Caption = Application.Text(CDbl(TextBox1.Value - TextBox2.Value)
gt; / (TextBox3.Value - 1), quot;# ??/16quot;)
gt; End Sub
gt;
gt; If I am in textbox2 and enter a value, it works fine, if I want to
gt; change the value by pressing back space I get a error, because (I
gt; assume, it becomes a zero error)
gt;
gt; ..is there a way to trap this error and still be able to stay in the
gt; textbox?
--
Dave Peterson
Just a slight rearrangement of code to fix the caption if there are errors:
Option Explicit
Private Sub TextBox2_Change()
Me.Label7.Caption = quot;quot;
If IsNumeric(Me.TextBox1.Value) _
And IsNumeric(Me.TextBox2.Value) _
And IsNumeric(Me.TextBox3.Value) Then
If Me.TextBox3.Value lt;gt; 1 Then
Me.Label7.Caption _
= Format(CDbl(TextBox1.Value - TextBox2.Value) _
/ (TextBox3.Value - 1), quot;# ??/16quot;)
End If
End If
End Sub
Dave Peterson wrote:
gt;
gt; I think I'd check to make sure everything was numeric and that textbox3.value
gt; was different than 1 (no div/0 errors):
gt;
gt; Option Explicit
gt; Private Sub TextBox2_Change()
gt;
gt; If IsNumeric(Me.TextBox1.Value) _
gt; And IsNumeric(Me.TextBox2.Value) _
gt; And IsNumeric(Me.TextBox3.Value) Then
gt; If Me.TextBox3.Value lt;gt; 1 Then
gt; Me.Label7.Caption _
gt; = Format(CDbl(TextBox1.Value - TextBox2.Value) _
gt; / (TextBox3.Value - 1), quot;# ??/16quot;)
gt; Else
gt; Me.Label7.Caption = quot;quot;
gt; End If
gt; End If
gt; End Sub
gt;
gt; And Format worked ok for me instead of application.text--not all number formats
gt; can be done this way, but this one was ok.
gt;
gt; damorrison wrote:
gt; gt;
gt; gt; I have text boxes and labels that show values, using formulas such as
gt; gt; the code below for Label7:
gt; gt;
gt; gt; Private Sub TextBox2_Change()
gt; gt; Label7.Caption = Application.Text(CDbl(TextBox1.Value - TextBox2.Value)
gt; gt; / (TextBox3.Value - 1), quot;# ??/16quot;)
gt; gt; End Sub
gt; gt;
gt; gt; If I am in textbox2 and enter a value, it works fine, if I want to
gt; gt; change the value by pressing back space I get a error, because (I
gt; gt; assume, it becomes a zero error)
gt; gt;
gt; gt; ..is there a way to trap this error and still be able to stay in the
gt; gt; textbox?
gt;
gt; --
gt;
gt; Dave Peterson
--
Dave Peterson
Thanks, this works
tmp = tmp CDbl(TextBox2.Value) should have been
tmp = tmp - CDbl(TextBox2.Value)
Dave,
your code displays the whole number then ??/16 (for the fraction) in
the label I don't know whyUse application.text() instead of format(). (I didn't notice it before.)
damorrison wrote:
gt;
gt; Thanks, this works
gt; tmp = tmp CDbl(TextBox2.Value) should have been
gt; tmp = tmp - CDbl(TextBox2.Value)
gt;
gt; Dave,
gt; your code displays the whole number then ??/16 (for the fraction) in
gt; the label I don't know why
--
Dave Peterson
I didn't notice that, either
Thanks
- Dec 18 Mon 2006 20:34
error in userform
close
全站熱搜
留言列表
發表留言