• Common code (Access 2000)

    Author
    Topic
    #405302

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #831319

      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..

      • #831335

        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

        • #831397

          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])

      • #831336

        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

    • #831320

      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..

    Viewing 1 reply thread
    Reply To: Common code (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: