Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Format textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vagante - 02 Mar 2005 13:42 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.