+ Reply to Thread
Results 1 to 3 of 3

Need UserForm Assistance with Forcing numeric input

  1. #1
    Registered User
    Join Date
    04-14-2005
    Posts
    12

    Red face Need UserForm Assistance with Forcing numeric input

    Hey all,

    There was a post with a similar problem, but the answer didn't really make sense to me and I couldn't reapply the code to my form, so maybe someone can help (I've only been programming for about a year now).

    Here's what I'm pulling my hair out over: I have a Userform with multiple entries (5 text, 5 radio). Two of these text boxes are formatted on the form & worksheet as numbers (lngPhoneNum and lngOrderNum) and the length is set by the Form textbox, so that's okay.

    What I need to do is to prevent any other characters than numbers from being entered into the Textboxes. Is there a way to disable any other input than numeric values?

    While I'm at it, let me ask a couple of other questions regarding the vars
    -Since the Worksheet is already fromatted, does it matter if these are Dim'd as String or Long?
    -Lastly, would this be a seperate sub since the buttons are the only objects I have coded (Submit, Clear, Save&Exit)?

    Whew! Sorry for the barrage, but any help would be greatly appreciated.

    -Bri

  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Forcing numeric characters only at entry time in a text box on a user form

    To answer your question:
    -Since the Worksheet is already fromatted, does it matter if these are Dim'd as String or Long?
    It can, depending if the numeric requires leading zeroes, if you need to export it to other systems, etc.

    To answer your question:
    -Lastly, would this be a seperate sub since the buttons are the only objects I have coded (Submit, Clear, Save&Exit)?
    Yes...

    Use the Change event of the text box in combination with the IsNumeric function to execute a validation of each keystroke entered into a textbox and alert the user with the MsgBox function if the character entered isn't a number. It executes after EVERY keystroke - adding as well as deleting characters. The sample code below will remove the non-numeric character entered if the user selects the 'Retry' option or clear the text box completely if the user selects the 'Cancel' option in the alert dialog.


    Copy the code below to the code page of your user form (change reference to the textbox name to your own):
    Please Login or Register  to view this content.
    Hope this helps,
    theDude

  3. #3
    Registered User
    Join Date
    04-14-2005
    Posts
    12
    Works like a charm. Thanks so much, Dude.

    You rock!!!

+ 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