Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Common code (Access 2000)

    In my modules made public, i have several functions where i must set the variables each time
    for each function.
    For example :
    Set chickens = [Forms]![Farm]![Subform].[Form].[Quantity]
    Set poultry = [Forms]![Farm]![Subform].[Form].[cartons]
    Set customer = main![Customerid]
    etc
    etc

    Since i have more variables to set, i would like to ask is there any way to put these setting in the general section of the code and to be made public to
    all the functions in the database?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Common code (Access 2000)

    Your code is setting object variables. Is that what you intended? It is possible to use global variables but they are highly breakable. Any unhandled error in code will reset all the variables breaking any code that depends on them. There may be other ways to handle what you're trying to do but you will have to explain further, since your examples are not self-explanatory..
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Common code (Access 2000)

    thank you for your reply.I have a module called MdUpdate. This module contains 5 functions. The first function is called FncTown.The second is called
    FncBenches. In each function i have to set one and the same variables. Instead of setting them for each function, is it possible to set the variables only once,
    before the functions, so that instead of writing them 5 times, to write them only once

    regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Common code (Access 2000)

    You could pass the values as arguments to the function:

    Public Function FncTown(chickens As Long, poultry As Long, customer As Long)
    ...
    End Function

    Call it like this:

    FncTown [Forms]![Farm]![Subform].[Form].[Quantity], [Forms]![Farm]![Subform].[Form].[cartons], Forms!Farm![Customerid]

    or

    =FncTown([Forms]![Farm]![Subform].[Form].[Quantity], [Forms]![Farm]![Subform].[Form].[cartons], Forms!Farm![Customerid])

Posting Permissions

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