+ Reply to Thread
Results 1 to 3 of 3

UserForm Control

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    UserForm Control

    I have a userform with approximately 150 individual text boxes that will be used for numerical entry.

    I have the following code set up for each and every text box that is to be used for numerical entry.
    Private Sub txtRawP1P2Day_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    '   Limit entry to only numerical data
        If Not ((KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 44 _
            Or KeyAscii = 45 Or KeyAscii = 46) Then KeyAscii = 0
    End Sub
    Private Sub txtRawP1P2Day_AfterUpdate()
        txtRawP1P2Day.Text = FormatNumber(txtRawP1P2Day.Text, 2)
    End Sub
    My form works, thanks to some advice I have either read here or had questions answered here.

    My question is for future reference. Is there a more efficient way of accomplishing this. Again, basically just limit what can be entered to numerical data and then format the display to a common numerical format.

    This just seems very bulky to do the same thing over, and over, and over.
    Thanks!
    Dennis

    I am using Windows 7 and Office 2007, all of my posts are based on this.

  2. #2
    Forum Contributor
    Join Date
    03-24-2004
    Location
    Edam Netherlands
    Posts
    181
    Maybe...?

    
    Private Sub txtRawP1P2Day_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    
    '   Limit entry to only numerical data
        If Not ValidAscii(KeyAscii) Then KeyAscii = 0
    
    End Sub
    
    Private Function ValidAscii(ByVal AsciiKey As Integer) As Boolean
    
        ValidAscii = False
        
        If AsciiKey >= 44 And AsciiKey <= 57 Then
           If AsciiKey <> 47 Then ValidAscii = True
        End If
    
    End Function

  3. #3
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Thank You

    I had thought about using a function, but really didn't see what I would gain.

    But this approach will definitely shorten the overall code.

    I was hoping to find a way to simplify having to put the same thing in 150 individual text box events.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1