Question For Microsoft Access Data Base

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joeldault
    New Member
    • Jan 2010
    • 20

    #1

    Question For Microsoft Access Data Base

    Question For Microsoft Access Data Base
    --------------------------------------------------------------------------------

    I am Trying to create a single formula that would do the following:

    If A1 is less then or equal to 499, deliver B1*1, if A1 is equal to or less than 999 but more than and including 500, deliver B1*2, If A1 is equal to or less than 1499 but more than and including 1000, deliver B1*3, AND SO ON.....

    I have read the Posts on this and they don't Work

    =Int(A1/500)*B1 Dont work, It gives the wrong values for 500, 1000, 1500, etc

    +Int(A1/500+1)-(MOD(A1,500)=0 Dont work, I cant get Access to except this formula. It wont save. It changes back to whatever was in the Control Source.

    I am not an expert at this and the third response from what I can tell looks like an answer for Excel and not Access, Well I cant figure it out. Creating the Table which is the first part makes no since on how to do it.

    That post was as follows:
    [This followup was posted to microsoft.publi c.excel.workshe et.functions
    with an email copy to =?Utf-8?B?QW1hbg==?=.
    Please use the newsgroup for further discussion.]

    Three possibilities, in addition to the option already discussed by
    others, are below. None of the options requires the thresholds to be
    equally spaced, nor that the return values be 1,2,3, etc.

    1) Use the formula =B1*(IF(A1<=0,0 ,IF(A1<=500,1,I F(A1<=1000,2,3) )))
    This might be the easiest to understand but it has two limitations.
    First, IF statements can be nested only 7 deep. There are ways around
    the limitation, but they just complicate the matter further. Second,
    the thresholds and the returned values are hidden in the formula and
    not immediately obvious from looking at the worksheet.

    2) Create a table such as:
    F G
    2 0 1
    3 500 2
    4 1000 3

    And, use the formula
    Code:
    =B1*INDEX(G2:G4,MATCH(A1,F2:F4,1)-(A1=INDEX(F2:F4,MATCH(A1,F2:F4,1))))
    The 2nd part -- following the -( part -- is an adjustment for the fact
    that you want the conditions to be 'less than or equal to'. The
    advantage of this formula is that it is easy to adjust for more
    conditions. The downside is that it might be somewhat intimidating to
    a novice.

    3) Use the VBA user defined function (UDF) given below as
    =TieredPricing( F2:G4,A1,TRUE). The advantage is that it makes the
    worksheet more 'self documented' and it further separates the code from
    the data. The downside is the need for a VBA module and having to deal
    with the accompanying 'This file contains macros' warning.
    Code:
    Function TieredPricing(LookupTable As Range, LookupValue As Double, _
    Optional IncludeBoundaryValue As Boolean = False)
    Dim Rslt As Variant
    On Error Resume Next
    Rslt = Application.WorksheetFunction.Match( _
    LookupValue, LookupTable.Columns(1), 1)
    If Not IsEmpty(Rslt) Then
    If IncludeBoundaryValue _
    And LookupTable.Cells(Rslt, 1).Value = LookupValue Then
    If Rslt = 1 Then _
    TieredPricing = _
    "Look up value outside of table values" _
    Else _
    TieredPricing _
    = LookupTable.Cells(Rslt - 1, 2).Value
    Else
    TieredPricing = _
    LookupTable.Cells(Rslt, 2).Value
    End If
    Else
    TieredPricing = "Look up value outside of table values"
    End If
    End Function
    None of this is working Please HELP

    Joel
    Last edited by NeoPa; Jan 3 '10, 10:02 PM. Reason: Please use the [CODE] tags provided
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    I would tend to create a Public Function in a standard module using a Select Case structure but you would have to finish the "AND SO ON" before code could be developed. It would be easier to understand and maintain later.

    Comment

    • joeldault
      New Member
      • Jan 2010
      • 20

      #3
      Thanks For your responce. What you are telling me. I Cant seam to get the Public Funtion to cross tables

      Comment

      • RuralGuy
        Recognized Expert Contributor
        • Oct 2006
        • 375

        #4
        If you are using this function in a form or query, I see no reason to cross tables. Are A and B in different tables? Do you have them joined in a query?
        The Function I had in mind would take the two values and return one.

        Comment

        • joeldault
          New Member
          • Jan 2010
          • 20

          #5
          This is what I am going.
          I have a From That I am trying to calulate State and County transfer tax. The County Charges 3.75 Cents per 500 and The State Charges 1.10 per 500. The From I am Creating is addiing the Costs. If I record a Mortgage it is 14.00 for the First page and 3.00 for each additional Page. The Form I have been able to put different kinds of docs in and get it to some the total on the form, but when I put in that a house dols for lets say 10,000.00. It need to give me the total of $8.60. If there was a way to send you the form I would.
          I had a public funtion working but it got to big and the program said i could not add more
          This is what I had
          Code:
           If "" & Me!Consideration < 499 Then
           Me!ConsiderationCal = 1
           Else
           If "" & Me!Consideration < 1000 Then
           Me!ConsiderationCal = 2
          Else
           If "" & Me!Consideration < 1499 Then
           Me!ConsiderationCal = 3
          Endif
          Endif
          Endif
          after I got to 250000.00 The Computer said I could not enter more
          Last edited by NeoPa; Jan 3 '10, 10:04 PM. Reason: Please use the [CODE] tags provided

          Comment

          • joeldault
            New Member
            • Jan 2010
            • 20

            #6
            Sorry Thanks for at least looking. I have been working on this for three days. all day and night. I cant get it to work

            Comment

            • nico5038
              Recognized Expert Specialist
              • Nov 2006
              • 3080

              #7
              I would create a function like:

              Code:
              Function fncMultiplier(lngI As Long) As Long
              
              fncMultiplier = 1
              While lngI > 500
                    fncMultiplier = fncMultiplier + 1
                    lngI = lngI - 500
              Wend
              
              End Function
              Place this code in a module.

              Now in the form field use:
              Code:
              =[B1] * fncMultiplier ([A1])
              Success,

              Nic;o)

              Comment

              • joeldault
                New Member
                • Jan 2010
                • 20

                #8
                I am sorry, The Funtion In the Public Code???, I have never done that before

                Comment

                • MMcCarthy
                  Recognized Expert MVP
                  • Aug 2006
                  • 14387

                  #9
                  Hi Joel

                  Try the following function and see if it gives you the results you want.
                  Code:
                  Dim totalSum as Long 'the represents the total value (10,000 in your example)
                  Dim i as Integer
                  Dim count as Integer
                  Dim rslt as Double
                  
                      For i=0 to totalSum Step 500
                          count = count +1
                      next i
                  
                      rslt = B1 * count ' should give you your result

                  Comment

                  • joeldault
                    New Member
                    • Jan 2010
                    • 20

                    #10
                    nico5038

                    That still seams to give off the wrong answer for 500, 1000, 1500 etc

                    Comment

                    • joeldault
                      New Member
                      • Jan 2010
                      • 20

                      #11
                      Thanks msquared
                      I will try that next

                      Comment

                      • joeldault
                        New Member
                        • Jan 2010
                        • 20

                        #12
                        nico5038
                        I am sorry, My Thinking is wrong. I am not even sure at thhis moment if that is right or not. Sorry I need to think

                        Comment

                        • joeldault
                          New Member
                          • Jan 2010
                          • 20

                          #13
                          nico5038
                          Thats it. Thanks, Three Days I have been wooking on this

                          Comment

                          • joeldault
                            New Member
                            • Jan 2010
                            • 20

                            #14
                            nico5038

                            how do i get it not to calulate o.oo

                            Comment

                            • joeldault
                              New Member
                              • Jan 2010
                              • 20

                              #15
                              Function fncMultiplier(l ngI As Long) As Long

                              fncMultiplier = 1
                              While lngI > 500
                              fncMultiplier = fncMultiplier + 1
                              lngI = lngI - 500
                              Wend

                              End Function

                              This Works great expect for $0.00 gives a Errior. Is there a way to fix this

                              Comment

                              Working...