Results 1 to 10 of 10

Thread: call a function

  1. #1
    Join Date
    Dec 2004
    Posts
    277

    Unanswered: call a function

    how do you call a function in access? if i have the code save in a module.. how do I tell a command button to use it?

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    =YourFunctionName() goes in the button's OnClick event on the property sheet
    Inspiration Through Fermentation

  3. #3
    Join Date
    Sep 2003
    Posts
    41

    try this

    in your buttons on click event put this code


    docmd.runcommand "name of function() without qoutes"

    mine look like this


    docmd.runcommand docidlookup()

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Quote Originally Posted by opcbriley
    in your buttons on click event put this code


    docmd.runcommand "name of function() without qoutes"

    mine look like this


    docmd.runcommand docidlookup()
    Interesting....
    I didn't know you could do it that way.
    It's not necessary, though.
    In this case, you could just put

    ...
    docidlookup
    ...

    in your code, and access would call that function.
    Inspiration Through Fermentation

  5. #5
    Join Date
    Dec 2004
    Posts
    277
    thank you all once again

  6. #6
    Join Date
    Sep 2003
    Posts
    41

    nice way to do it

    didnt know i could do that. can you have two lines that way.

    for instance


    docmd.setwarnings false
    "=functionamehere"

    all on the properties sheet.

  7. #7
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    You would have to either:
    create a macro to do those steps, and put the macro name in the On Click event

    or

    Use the Code Builder for the On Click event and put in:

    ...
    Docmd.Setwarning False
    YourFunctionName
    ...
    Inspiration Through Fermentation

  8. #8
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Talking

    Quote Originally Posted by opcbriley
    didnt know i could do that. can you have two lines that way.

    for instance


    docmd.setwarnings false
    "=functionamehere"

    all on the properties sheet.
    PLEASE BE CAREFUL!!!!! Please don't forget to set your warnings back ON when done. So many users have forgotten this and when they had ActionQueries running they wouldn't know it.

    Have a nice one
    BUD

  9. #9
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Also make sure your function/sub is declared as public.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  10. #10
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Quote Originally Posted by Teddy
    Also make sure your function/sub is declared as public.
    Hey Teddy....

    I think you probably know this so please enlighten me. When I write a function and it includes running a query, I avoid doing the SetWarnings thing by doing:

    CurrentDB.Execute "myQueryHere"

    Does CurrentDB.Execute ONLY work for Queries? Isn't that the only time you would possibly even bother with the SetWarnings thingy? Still trying to learn more.

    thanks
    BUD

Posting Permissions

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