Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Feb 2003
    Thanked 0 Times in 0 Posts

    Referencing a user-defined function (Access2K, Office2K Pro)

    This is related to teh earlier post on generating Quarterly date ranges on-the fly. I wrote some code in a module that takes an input (EnterYear) and produces the required quarterly ranges. I've never tried to make a function, so I'm a bit puzzled as to how I can access my code now that I've written it.

    I have got to this point:

    Function Quarters()


    End Function

    and can click on the run button in VBA and, since I have an input box in the code, it pops up to accept a year and displays the quarters. Groovy. HOWEVER, when I try to do RunCode in a macro (just to see if it'll run) I get 'The expression you entered has a function name that Access can't find'. I thought, well, perhaps I should put something in the () of the function declaration, like (EnterYear) [the name of the variable] -- so I do that and when I click on thr run button in VBA, the Macros dialog box pops up with no macros listed. I tried creating one called Quarters but it says the name conflicts with an existing module, project or library.

    OK, don't understand that. I go back to the Macro, do RunCode and type in Quarters(2000) and the same 'The expression you entered has a function name that Access can't find' error shows up.

    OK, no progress. I go back to VBA and try Quarters(EnterYear as Integer); no progress. The only thing that I can do is delete the () content and the function runs in VBA but no where else.


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Referencing a user-defined function (Access2K, Office2K Pro)

    If you have named one of your modules Quarters, this conflicts with the function named Quarters. You will still be able to run the function from within the module it resides in, but it will be invisible from other parts of the database.

    If your function definition doesn't have arguments, you shouldn't use an argument when you call it in a macro or elsewhere.

Posting Permissions

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