Results 1 to 5 of 5

Thread: [RESOLVED] Argument Not Option Error When calling a sub within a sub....

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Argument Not Option Error When calling a sub within a sub....

    This is what MSDN says about my problem:
    The number and types of arguments must match those expected. This error has the following causes and solutions:

    Incorrect number of arguments.
    Supply all necessary arguments. For example, the Left function requires two arguments; the first representing the character string being operated on, and the second representing the number of characters to return from the left side of the string. Because neither argument is optional, both must be supplied.

    Omitted argument isn't optional.
    An argument can only be omitted from a call to a user-defined procedure if it was declared Optional in the procedure declaration. Either supply the argument in the call or declare the parameter Optional in the definition.

    For additional information, select the item in question and press F1.
    I get the error on the following:
    VB Code:
    1. Private Sub mnuFileMenuExit_Click()
    2.     Form_Unload
    3. End Sub
    and Form_Unload looks like so:
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     If frmBRLOutput.Visible Then
    3.         Unload frmBRLOutput
    4.     End If
    5.    
    6.     If frmAbout.Visible Then
    7.         Unload frmAbout
    8.     End If
    9.    
    10.     Unload Me
    11. End Sub
    Is there a way I can call the Unload_Form sub from within the mnuFileMenuExit_Click event or do I have to add the code to a module and then call it? Please advise.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: Argument Not Option Error When calling a sub within a sub....

    Calling Event Subs isn't the best practice. That aside you are aware you need a parameter.
    Having said that, try this instead (not directly call in the Event Sub) like:
    VB Code:
    1. Private Sub mnuFileMenuExit_Click()
    2.     [b]Unload Me[/b]
    3. End Sub
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: Argument Not Option Error When calling a sub within a sub....

    And..
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     If frmBRLOutput.Visible Then
    3.         Unload frmBRLOutput
    4.     End If
    5.    
    6.     If frmAbout.Visible Then
    7.         Unload frmAbout
    8.     End If
    9.    
    10.     Unload Me '<<<<<< that isnt required!
    11.  
    12.     [b]Cancel = False[/b]
    13.  
    14. End Sub
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Argument Not Option Error When calling a sub within a sub....

    ok, thanks Bruce Fox. always wondered what the cancel as integer was for.

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: [RESOLVED] Argument Not Option Error When calling a sub within a sub....

    You can set it to True in the event the Form shouldn't be unloaded. Eg. if the Form was closed (or attempted to be closed) using the 'x' instead ot a dedicated 'close' button.
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

Posting Permissions

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



Click Here to Expand Forum to Full Width