+ Reply to Thread
Results 1 to 4 of 4

error message: compile error, argument not optional

  1. #1
    Pierre via OfficeKB.com
    Guest

    error message: compile error, argument not optional

    Hi,

    I have a txt_box in a userform called txt_staf1 where the user can put in a
    number for example 2,5 or 25,8.

    I have the following code with the txt_box

    Private Sub txt_staf1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    OnlyNumbers
    rekenen
    End Sub

    where 'rekenen' is a sub that makes the sheet recalculate.

    I check if the input is a number using the sub OnlyNumbers:

    Private Sub OnlyNumbers(ctl As Object)
    With ctl
    If Not IsNumeric(Left(.Value, 1)) And .Value <> vbNullString Then
    MsgBox "Sorry, alleen getallen toegestaan", vbOKOnly, "De Pensioen
    Adviseur"
    .Value = vbNullString
    .SetFocus
    End If
    End With
    End Sub

    When the user puts in a number i get the error message: compile error,
    argument not optional
    Does anybody know what is wrong ?
    thanks,
    Jean-Pierre


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

  2. #2
    Norman Jones
    Guest

    Re: error message: compile error, argument not optional

    Hi Jean-Pierre,

    Try changing:

    > Private Sub txt_staf1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    > OnlyNumbers
    > rekenen
    > End Sub


    to:

    Private Sub txt_staf1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    OnlyNumbers txt_staf1
    rekenen
    End Sub


    ---
    Regards,
    Norman



    "Pierre via OfficeKB.com" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I have a txt_box in a userform called txt_staf1 where the user can put in
    > a
    > number for example 2,5 or 25,8.
    >
    > I have the following code with the txt_box
    >
    > Private Sub txt_staf1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    > OnlyNumbers
    > rekenen
    > End Sub
    >
    > where 'rekenen' is a sub that makes the sheet recalculate.
    >
    > I check if the input is a number using the sub OnlyNumbers:
    >
    > Private Sub OnlyNumbers(ctl As Object)
    > With ctl
    > If Not IsNumeric(Left(.Value, 1)) And .Value <> vbNullString
    > Then
    > MsgBox "Sorry, alleen getallen toegestaan", vbOKOnly, "De
    > Pensioen
    > Adviseur"
    > .Value = vbNullString
    > .SetFocus
    > End If
    > End With
    > End Sub
    >
    > When the user puts in a number i get the error message: compile error,
    > argument not optional
    > Does anybody know what is wrong ?
    > thanks,
    > Jean-Pierre
    >
    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.a...mming/200509/1




  3. #3
    Pierre via OfficeKB.com
    Guest

    Re: error message: compile error, argument not optional

    Hi Norman,

    thanks for your input...it works !
    Strange thing is that i have numerous txt_boxes where i do the same
    calculation but not need to add the txt_box name behind the OnlyNumbers sub..
    ..

    Norman Jones wrote:
    >Hi Jean-Pierre,
    >
    >Try changing:
    >
    >> Private Sub txt_staf1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    >> OnlyNumbers
    >> rekenen
    >> End Sub

    >
    >to:
    >
    > Private Sub txt_staf1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    > OnlyNumbers txt_staf1
    > rekenen
    >End Sub
    >
    >---
    >Regards,
    >Norman
    >
    >> Hi,
    >>

    >[quoted text clipped - 31 lines]
    >> thanks,
    >> Jean-Pierre



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

  4. #4
    Dave Peterson
    Guest

    Re: error message: compile error, argument not optional

    You have an alternative at your first post.

    "Pierre via OfficeKB.com" wrote:
    >
    > Hi,
    >
    > I have a txt_box in a userform called txt_staf1 where the user can put in a
    > number for example 2,5 or 25,8.
    >
    > I have the following code with the txt_box
    >
    > Private Sub txt_staf1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    > OnlyNumbers
    > rekenen
    > End Sub
    >
    > where 'rekenen' is a sub that makes the sheet recalculate.
    >
    > I check if the input is a number using the sub OnlyNumbers:
    >
    > Private Sub OnlyNumbers(ctl As Object)
    > With ctl
    > If Not IsNumeric(Left(.Value, 1)) And .Value <> vbNullString Then
    > MsgBox "Sorry, alleen getallen toegestaan", vbOKOnly, "De Pensioen
    > Adviseur"
    > .Value = vbNullString
    > .SetFocus
    > End If
    > End With
    > End Sub
    >
    > When the user puts in a number i get the error message: compile error,
    > argument not optional
    > Does anybody know what is wrong ?
    > thanks,
    > Jean-Pierre
    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.a...mming/200509/1


    --

    Dave Peterson

+ 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