Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2008
    Location
    Suburb of Chicago, Illinois
    Posts
    56

    Unanswered: Help to link Module to Field in Query

    I'm using Access 2003.
    I put code that defines a field into a module named CreditItem1.
    See following code.
    I also defined a report field named CreditItem in my query.
    How do I link the module to the field in my query?
    ================================================== ==
    Private Function CreditItem1()

    If rs![InvoiceHeader.BillingType] = "RE" Then CreditItem1 (rs![InvoiceDetail.TotalNetPrice] - rs![InvoiceDetail.FreightPrice]) * -1
    If rs![TonerCategory] = "B5" Then CreditItem1 rs![Toner] * 1
    If rs![TonerCategory] = "Bndl" Then CreditItem1 rs![Toner] * 155
    If rs![InvoiceDetail.TotalNetPrice] - rs![InvoiceDetail.FreightPrice] Then CreditItem1

    End Function
    ================================================== ====

    Thanks,

    Krazy

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    For a start you have to declare the function as Public, not Private
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2008
    Location
    Suburb of Chicago, Illinois
    Posts
    56

    Thanks George

    Thanks George.
    I'll make the cgane.
    I look forward to any other input.

    Krazy

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Next you need to make sure the code actually works.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Mar 2008
    Location
    Suburb of Chicago, Illinois
    Posts
    56

    No Errors

    I compiled it and there are no errors.
    I think the next step is to somehow link it to my report query and see what the results are. Can you tell me how to link it?

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Normally you'd connect a report field by it's Control Source. You might put in something like =CreditItem1().

    The code is referring to an undefined object "rs". I also think your basic syntax of the code after Then needs to be studied out and corrected. For example, it's not CreditItem1 (rs![InvoiceDetail.TotalNetPrice] - rs![InvoiceDetail.FreightPrice]) * -1 but CreditItem1 = (rs![InvoiceDetail.TotalNetPrice] - rs![InvoiceDetail.FreightPrice]) * -1

    I think you have more problems than just connecting your function to the field

    I think you also need to make sure you know how to deal with arguments in a function. For example, instead of using rs![TonerCategory], you need to pass the function, say, a strTonerCategory variable and use that in your code.

    To start off your study, look at this example of using a function with an argument.

    Public Function Quad (intNumberGiven as Double)
    Quad = intNumberGiven ^ 4
    End Function

    You'd call it by using an expression such as Quad(3).

    Hope that helps

    ST
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Mar 2008
    Location
    Suburb of Chicago, Illinois
    Posts
    56
    Thanks.
    I'll keep working on the application.

    Krazy

Posting Permissions

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