+ Reply to Thread
Results 1 to 6 of 6

Using public function from userform

  1. #1
    Registered User
    Join Date
    09-01-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    11

    Using public function from userform

    Hi!

    I have this boolean function:

    Please Login or Register  to view this content.
    which is used to determin whether the date d1 is is a national holiday. This function works well when using it from a test-sub in the same module:

    Please Login or Register  to view this content.
    But, when I try to use it from within a userform, I get the error message "Compile error: ByRef argument type mismatch". The code I use in the userform is (extract):
    Please Login or Register  to view this content.
    What can be the reason for this? The d1 variable is declared as date both places...

    Thx in advance for any help!
    Attached Files Attached Files
    Last edited by Geronimo; 09-06-2010 at 02:34 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388

    Re: Problem using public function from userform

    It's because dato is a Variant.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Problem using public function from userform

    or

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by snb; 09-01-2010 at 06:07 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Problem using public function from userform

    If the date is not found, then trying to access the address will return a run time error.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    09-01-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Problem using public function from userform

    Update:
    Thanks for all help :-)
    I found a quick fix for my problem - just by adding a "ByVal" in the definition of the public function (I think "ByRef" is default?).

    Please Login or Register  to view this content.
    Case solved :-)

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Problem using public function from userform

    Please mark the thread 'Solved' then.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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