Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Data validation (WD97)

    I need to validate data that has been input textboxes. The only format available is positive integers. Is there reliable code somewhere that I can use to get this done?
    Thanks in advance

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Data validation (WD97)

    This will validate the info after the OK button is clicked in to InputBox;

    <pre>Sub ReturnPositiveIntegerOnly()

    Dim strReturn As String
    Dim lngReturn As Long

    On Error GoTo Handle_Error
    Do
    strReturn = InputBox("Enter a positive integer")
    lngReturn = CLng(strReturn)
    Loop Until (lngReturn >= 0)

    Exit Sub

    Handle_Error:

    Select Case Err.Number
    Case 13
    'This will occur if you enter text into the input box, so we need
    ' to return anegative value so the code loops again
    lngReturn = -1
    Resume Next
    Case Else
    MsgBox Err.Number & vbCrLf & Err.Description
    End Select

    End Sub</pre>

    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

Posting Permissions

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