+ Reply to Thread
Results 1 to 8 of 8

check is input textboxes is numeric on userform

  1. #1
    Jean-Pierre D via OfficeKB.com
    Guest

    check is input textboxes is numeric on userform

    Hi,

    I have a multipage userform.
    on one of the pages there are 10 text boxes that may only contain numbers( or
    a percentage)

    I now use the following code:

    Private Sub nw_premieNP_change()
    OnlyNumbers
    End Sub

    and then the following sub:

    Private Sub OnlyNumbers()
    With nw_premieNP.ActiveControl
    If Not IsNumeric(.Value) And .Value <> vbNullString Then
    MsgBox "Sorry, alleen getallen toegestaan"
    .Value = vbNullString
    End If
    End With
    End Sub

    This works perfectly but i have to do this for each textbox. so i get 20 subs
    !
    Is there a better way to do this for all the textboxes in the userform page?

    Thanks,
    Jean-Pierre


    --
    Message posted via http://www.officekb.com

  2. #2
    Bob Phillips
    Guest

    Re: check is input textboxes is numeric on userform

    Pass the control to the Sub

    Private Sub nw_premieNP_change()
    OnlyNumbers nw_premieNP
    End Sub

    Private Sub nw_secondNP_change()
    OnlyNumbers nw_secondNP
    End Sub


    and then the following sub:

    Private Sub OnlyNumbers(ctl As Object)
    With ctl.ActiveControl
    If Not IsNumeric(.Value) And .Value <> vbNullString Then
    MsgBox "Sorry, alleen getallen toegestaan"
    .Value = vbNullString
    End If
    End With
    End Sub


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Jean-Pierre D via OfficeKB.com" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I have a multipage userform.
    > on one of the pages there are 10 text boxes that may only contain

    numbers( or
    > a percentage)
    >
    > I now use the following code:
    >
    > Private Sub nw_premieNP_change()
    > OnlyNumbers
    > End Sub
    >
    > and then the following sub:
    >
    > Private Sub OnlyNumbers()
    > With nw_premieNP.ActiveControl
    > If Not IsNumeric(.Value) And .Value <> vbNullString Then
    > MsgBox "Sorry, alleen getallen toegestaan"
    > .Value = vbNullString
    > End If
    > End With
    > End Sub
    >
    > This works perfectly but i have to do this for each textbox. so i get 20

    subs
    > !
    > Is there a better way to do this for all the textboxes in the userform

    page?
    >
    > Thanks,
    > Jean-Pierre
    >
    >
    > --
    > Message posted via http://www.officekb.com




  3. #3
    K Dales
    Guest

    RE: check is input textboxes is numeric on userform

    I don't know any way to do this unless you are willing to create a custom
    class. For the 20 textboxes you have it is probably easiest just to do as
    you have done. If you think you may need to do this repeatedly in the
    future, look into class modules and custom classes to create your own objects
    that use existing objects but add new features and functionality. Too much
    to get into here but lots of online references if you search.
    --
    - K Dales


    "Jean-Pierre D via OfficeKB.com" wrote:

    > Hi,
    >
    > I have a multipage userform.
    > on one of the pages there are 10 text boxes that may only contain numbers( or
    > a percentage)
    >
    > I now use the following code:
    >
    > Private Sub nw_premieNP_change()
    > OnlyNumbers
    > End Sub
    >
    > and then the following sub:
    >
    > Private Sub OnlyNumbers()
    > With nw_premieNP.ActiveControl
    > If Not IsNumeric(.Value) And .Value <> vbNullString Then
    > MsgBox "Sorry, alleen getallen toegestaan"
    > .Value = vbNullString
    > End If
    > End With
    > End Sub
    >
    > This works perfectly but i have to do this for each textbox. so i get 20 subs
    > !
    > Is there a better way to do this for all the textboxes in the userform page?
    >
    > Thanks,
    > Jean-Pierre
    >
    >
    > --
    > Message posted via http://www.officekb.com
    >


  4. #4
    Jean-Pierre D via OfficeKB.com
    Guest

    Re: check is input textboxes is numeric on userform

    thanks Bob, this works for me!
    JP

    Bob Phillips wrote:
    >Pass the control to the Sub
    >
    >Private Sub nw_premieNP_change()
    > OnlyNumbers nw_premieNP
    >End Sub
    >
    >Private Sub nw_secondNP_change()
    > OnlyNumbers nw_secondNP
    >End Sub
    >
    >and then the following sub:
    >
    >Private Sub OnlyNumbers(ctl As Object)
    > With ctl.ActiveControl
    > If Not IsNumeric(.Value) And .Value <> vbNullString Then
    > MsgBox "Sorry, alleen getallen toegestaan"
    > .Value = vbNullString
    > End If
    > End With
    >End Sub
    >
    >> Hi,
    >>

    >[quoted text clipped - 25 lines]
    >> Thanks,
    >> Jean-Pierre



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200508/1

  5. #5
    Jean-Pierre D via OfficeKB.com
    Guest

    Re: check is input textboxes is numeric on userform

    Hi Bob,

    I get an error message on the 'ctl.active.control' in your onlynumbers sub....

    any ideas for improvement ?
    Thanks,
    JP

    Bob Phillips wrote:
    >Pass the control to the Sub
    >
    >Private Sub nw_premieNP_change()
    > OnlyNumbers nw_premieNP
    >End Sub
    >
    >Private Sub nw_secondNP_change()
    > OnlyNumbers nw_secondNP
    >End Sub
    >
    >and then the following sub:
    >
    >Private Sub OnlyNumbers(ctl As Object)
    > With ctl.ActiveControl
    > If Not IsNumeric(.Value) And .Value <> vbNullString Then
    > MsgBox "Sorry, alleen getallen toegestaan"
    > .Value = vbNullString
    > End If
    > End With
    >End Sub
    >
    >> Hi,
    >>

    >[quoted text clipped - 25 lines]
    >> Thanks,
    >> Jean-Pierre



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200508/1

  6. #6
    Bob Phillips
    Guest

    Re: check is input textboxes is numeric on userform

    JP,

    I got that also, but as the ActiveControl property was part of your original
    code, I thought it must work for you.

    What is ActiveControl?

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Jean-Pierre D via OfficeKB.com" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Bob,
    >
    > I get an error message on the 'ctl.active.control' in your onlynumbers

    sub....
    >
    > any ideas for improvement ?
    > Thanks,
    > JP
    >
    > Bob Phillips wrote:
    > >Pass the control to the Sub
    > >
    > >Private Sub nw_premieNP_change()
    > > OnlyNumbers nw_premieNP
    > >End Sub
    > >
    > >Private Sub nw_secondNP_change()
    > > OnlyNumbers nw_secondNP
    > >End Sub
    > >
    > >and then the following sub:
    > >
    > >Private Sub OnlyNumbers(ctl As Object)
    > > With ctl.ActiveControl
    > > If Not IsNumeric(.Value) And .Value <> vbNullString Then
    > > MsgBox "Sorry, alleen getallen toegestaan"
    > > .Value = vbNullString
    > > End If
    > > End With
    > >End Sub
    > >
    > >> Hi,
    > >>

    > >[quoted text clipped - 25 lines]
    > >> Thanks,
    > >> Jean-Pierre

    >
    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.a...mming/200508/1




  7. #7
    Jean-Pierre D via OfficeKB.com
    Guest

    Re: check is input textboxes is numeric on userform

    Hi Bob,

    activecontrol is nothing but an error in my code...sorry.
    Do you know the right code tot do this?
    Thanks,
    JP

    Bob Phillips wrote:
    >JP,
    >
    >I got that also, but as the ActiveControl property was part of your original
    >code, I thought it must work for you.
    >
    >What is ActiveControl?
    >
    >> Hi Bob,
    >>

    >[quoted text clipped - 30 lines]
    >> >> Thanks,
    >> >> Jean-Pierre



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200508/1

  8. #8
    Bob Phillips
    Guest

    Re: check is input textboxes is numeric on userform

    Jean-Pierre,

    Give the simple

    With ctl

    a try first.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Jean-Pierre D via OfficeKB.com" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Bob,
    >
    > activecontrol is nothing but an error in my code...sorry.
    > Do you know the right code tot do this?
    > Thanks,
    > JP
    >
    > Bob Phillips wrote:
    > >JP,
    > >
    > >I got that also, but as the ActiveControl property was part of your

    original
    > >code, I thought it must work for you.
    > >
    > >What is ActiveControl?
    > >
    > >> Hi Bob,
    > >>

    > >[quoted text clipped - 30 lines]
    > >> >> Thanks,
    > >> >> Jean-Pierre

    >
    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.a...mming/200508/1




+ 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