Hi all,
I've created a userform in vba, but now i must have a textbox with a
specified format: it's a numeric textbox and i use this one, but the
format doesn't works.
Private Sub Lordo_Change()
On Error Resume Next
Netto.Value = Lordo.Value * 0.81699346 & Format(Netto.Value, "#.##0,00")
If Lordo.Value = "" Then
Netto.Value = ""
End If
End Sub
Then to let the user put in the textbox just numbers I've found this one
on the web.
There's just a problem: the user can put in two or more comma and i want
that the user can insert just one comma and just two numbers after the
comma.
Private Sub Lordo_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = FilterInput(KeyAscii:=KeyAscii.Value,
AllowNumeric:=True, AllowNegative:=False, AllowComma:=True,
AllowPoint:=True)
End Sub
'Function
Function FilterInput(KeyAscii As Integer, Optional AllowUpperCase As
Boolean = False, Optional AllowLowerCase As Boolean = False, Optional
AllowNumeric As Boolean = False, Optional AllowNegative As Boolean =
False, Optional AllowComma As Boolean = False, Optional AllowPoint As
Boolean = False) As Integer
Dim UCL As Integer, UCH As Integer
Dim LCL As Integer, LCH As Integer
Dim NUML As Integer, NUMH As Integer
Dim NEG As Integer, COM As Integer, PNT As Integer
NUML = -1
NUMH = -1
UCL = -1
UCH = -1
LCL = -1
LCH = -1
NEG = -1
COM = -1
PNT = -1
If AllowUpperCase Then
UCL = 65
UCH = 90
End If
If AllowLowerCase Then
LCL = 97
LCH = 122
End If
If AllowNumeric Then
NUML = 48
NUMH = 57
End If
If AllowNegative Then NEG = 45
If AllowComma Then COM = 44
If AllowPoint Then PNT = 46
Select Case KeyAscii
Case NUML To NUMH, UCL To UCH, LCL To LCH, NEG, COM, PNT
FilterInput = KeyAscii
Case Else
FilterInput = 0
End Select
End Function
Someone could please help an absolute newbie?
headly - 03 Mar 2005 03:05 GMT
I hate to offer you a 'lame' answer, but the function you are trying to
perform is better suited to a MS Access Data Access Page and could be written
with no coding. Just my 2 cents.
> Hi all,
> I've created a userform in vba, but now i must have a textbox with a
[quoted text clipped - 73 lines]
>
> Someone could please help an absolute newbie?
Vagante - 04 Mar 2005 15:29 GMT
> I hate to offer you a 'lame' answer, but the function you are trying to
> perform is better suited to a MS Access Data Access Page and could be written
> with no coding. Just my 2 cents.
Yes, thank you, but I need it in Word 2003.