Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Posts
    35

    Unanswered: Use Public Function?

    I was asked to make change in a database that now means that I have the need to have the same function used by multiple form buttons. I have tried to create a
    PUBLIC FUNCTION mymodule(), then cut the code from the private sub and pasted into this new section.

    On the PRIVATE SUB cmdbuttonclick(), I insert the code:
    mymodule() so that it would reference the above code
    End Sub

    I get a compile error. Is there an elegant way for a newbieprogrammer to share functions but have numerous buttons?

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Public function

    Are you sure you do not now have 2 public functions or a private and public function in the same mdb with the same name? Maybe do a search and check and see if you have 2 functions with the same name.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Jan 2006
    Posts
    35
    No duplicates. Just for testing, I tried a simple text string but it didnt work either.

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    where did you put this public function?

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Jan 2006
    Posts
    35
    Well, that might be where I messed up: it is just above where all of other procedures are.

  6. #6
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Best place for anything Public is in it's own module. Make a new module and place your public function there.

    Also, is it a SUB or a FUNCTION?

    A SUB is a Procedure. The best command line would be:
    Code:
    Call Module1.MyPublicSub()
    A FUNCTION returns some sort of value, so the command line should utilize the function as though it has a value:
    Code:
    strText = MyPublicFunction()
    hope this helps

Posting Permissions

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