It only trips an error when I "tab" into the field (upon which it turns blue) and then if a decimal point is entered as the first character I get:
"Run-time error '13:'
Type mismatch"
If I use the backspace key to remove any numerals that might be in the field, and then hit decimal (but its still the first character entered) then I do not get an error and it accepts the leading decimal.. (???)
(the RED code is where the error is highlighted)
Here is a screenshot of my form (part of it) showing the textboxes as mentioned in the above code:
Everything else in the code functions as intended (it sums up the totals just as it should), but I cant understand why it doesnt like it when a decimal point is entered as the first character, and only when the number that is present in the textbox is BLUE(as in highlighted) If I backspace over the character(s) that are in there, then hit the decimal point, it accepts it. (?) very strange....
"Run-time error '13:'
Type mismatch"
If I use the backspace key to remove any numerals that might be in the field, and then hit decimal (but its still the first character entered) then I do not get an error and it accepts the leading decimal.. (???)
(the RED code is where the error is highlighted)
Code:
[COLOR=#008000]' CODE FOR THE FIRST TEXT BOX FOR ALLOWING A DECIMAL POINT AS THE LEADING CHARACTER:[/COLOR]
Private Sub txtCostProd1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not (KeyAscii > 47 And KeyAscii < 59) Then
If KeyAscii = 46 And Len(txtCostProd1.Text) = 0 Then
txtCostProd1.Text = "0"
ElseIf Not (KeyAscii = 46 And InStr(txtCostProd1.Text, ".") = 0) Then
Beep: KeyAscii = 0
End If
End If
End Sub
[COLOR=#008000]' CODE FOR THE SECOND TEXT BOX FOR ALLOWING A DECIMAL POINT AS THE LEADING CHARACTER:[/COLOR]
Private Sub txtCostShip1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not (KeyAscii > 47 And KeyAscii < 59) Then
If KeyAscii = 46 And Len(txtCostShip1.Text) = 0 Then
txtCostShip1.Text = "0"
ElseIf Not (KeyAscii = 46 And InStr(txtCostShip1.Text, ".") = 0) Then
Beep: KeyAscii = 0
End If
End If
End Sub
Private Sub txtCostProd1_Change()
TextBoxesSum
End Sub
Private Sub txtCostShip1_Change()
TextBoxesSum
End Sub
Private Sub TextBoxesSum()
Dim Total As Double
Total = 0
If Len(txtCostProd1.Value) > 0 Then Total = [COLOR=#ff0000][B]Total + CDbl(txtCostProd1.Value)[/B][/COLOR]
If Len(txtCostShip1.Value) > 0 Then Total = Total + CDbl(txtCostShip1.Value)
txtCost1.Value = Total
End Sub
Here is a screenshot of my form (part of it) showing the textboxes as mentioned in the above code:
Everything else in the code functions as intended (it sums up the totals just as it should), but I cant understand why it doesnt like it when a decimal point is entered as the first character, and only when the number that is present in the textbox is BLUE(as in highlighted) If I backspace over the character(s) that are in there, then hit the decimal point, it accepts it. (?) very strange....
Last edited: