Dimitriy
12-19-2010, 08:39 PM
Hey Guys,
I have the following problem: I have a "Before Update" Private Sub for a form textbox that checks to make sure that the input is numeric and then converts it to a currency format. Here is the code:Private Sub txtIncBudAmount2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
'check for currency format
With txtIncBudAmount2
If .Text = "" Then
ElseIf IsNumeric(.Text) Then
.Text = Format(.Text, "Currency")
Else
MsgBox "Budget Amount format is incorrect. Standard format is #.##"
Cancel = True
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End If
End With
End Sub
I have about 35 textboxes like this. So in order to save some code lines I wanted to write a general Sub that will do this and then just pass it to a "Before Update" sub for each textbox.
For some reason I either getting an error or it throws Excel into a loop when I try to do this. I would really appreciate it if you could suggest a good way get this done.
Thanks!: pray2:
I have the following problem: I have a "Before Update" Private Sub for a form textbox that checks to make sure that the input is numeric and then converts it to a currency format. Here is the code:Private Sub txtIncBudAmount2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
'check for currency format
With txtIncBudAmount2
If .Text = "" Then
ElseIf IsNumeric(.Text) Then
.Text = Format(.Text, "Currency")
Else
MsgBox "Budget Amount format is incorrect. Standard format is #.##"
Cancel = True
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End If
End With
End Sub
I have about 35 textboxes like this. So in order to save some code lines I wanted to write a general Sub that will do this and then just pass it to a "Before Update" sub for each textbox.
For some reason I either getting an error or it throws Excel into a loop when I try to do this. I would really appreciate it if you could suggest a good way get this done.
Thanks!: pray2: