+ Reply to Thread
Results 1 to 7 of 7

Invalid procedure call error

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Invalid procedure call error

    Hi All

    I'm declaring a global variable and getting the above error message

    Please Login or Register  to view this content.
    Any help will be much appreciated.

    Thanks

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Invalid procedure call error

    Hi aman1234,

    It seems like you did not declare a Sub or Function. Your code should probably look something like:
    Please Login or Register  to view this content.
    The above code compiles fine with a value of '(TO>#12/01/2015# or TO IS null)'.

    Option Explicit is very important
    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Lewis

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Invalid procedure call error

    The sql1 = ... line must be in a sub

  4. #4
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Invalid procedure call error

    I need to use the value of sql1 many times in the code so that's why I want to define it globally so that I can use it as many times as I want . please see below:

    Please Login or Register  to view this content.
    Im getting invalid outside procedure error. Any help will be much appreciated.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Invalid procedure call error

    It must go in a sub, just make sure the sub runs before all your other code

  6. #6
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Invalid procedure call error

    kyle123, so how can I use the value of sql1 in combobox1_change() event?

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Invalid procedure call error

    Try something like:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-time error '5' - Invalid procedure call or argument
    By datutt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-14-2015, 12:12 PM
  2. Invalid procedure call or argument (Error 5)
    By vop2311 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2014, 07:27 PM
  3. Run-time error 5, Invalid procedure call or argument
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2014, 08:29 AM
  4. Run-time error '5': Invalid procedure call or argument
    By mcbruce76 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 07-30-2013, 08:31 PM
  5. error 'Invalid Procedure Call or Arguement'
    By chrismann85 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2009, 07:28 AM
  6. [SOLVED] Invalid procedure call or argument error
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2006, 06:45 PM
  7. [SOLVED] Run-time error '5': Invalid Procedure Call or Argument
    By Nikila in forum Excel General
    Replies: 2
    Last Post: 02-24-2006, 05:30 PM

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