Results 1 to 3 of 3

Thread: [RESOLVED] Expected Expression. Optional Arguments

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    PHL
    Posts
    5

    Resolved [RESOLVED] Expected Expression. Optional Arguments

    Hi, I hope someone can help me.
    I'm getting an error whenever I try to do this.

    Here is my code:

    Sub emp_filter(Optional ByVal cmbApprove As ComboBox = Nothing, Optional ByVal cmbDept As ComboBox = Nothing)
    ...
    End Sub


    I call it like this,
    This works: Call Class1.emp_filter( ,cmbdept)

    This doesn't: Call Class1.emp_filter(cmbApprove, ) <------------ Here is where i'm getting the error "Expected Expression"


    Is there a workaround for this aside from writing a new sub?

    Thanks!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Expected Expression. Optional Arguments

    You only include the comma before an argument. If you're omitting the first argument and supplying the second then you need the comma to show that the first argument is empty. If you're supplying the first but not the second then you don't need and, in fact, cannot use the comma. The compiler assumes that the first argument is for the first parameter because there's no comma before it, so there's no need to indicate that the second argument is empty.

    In short, get rid of the comma in the second code snippet.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    PHL
    Posts
    5

    Re: Expected Expression. Optional Arguments

    Awesome!
    Thanks jmcilhinney

Tags for this Thread

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