Results 1 to 6 of 6
  1. #1
    WSUAccess is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    3

    Pull maximum dollar amount in a paragraph

    I have thousands of paragraphs with dollar amounts, and I need to pull the dollar amount in each. I am querying a database, so I must use Access for this one. The dollar amount could be anywhere in the paragraph. Here are some examples of the dollar amount formats:

    $1,000 / $1000 / $1k / $45 / $585.

    Please help! I'm not smart enough to figure this one out. Thanks in Advance.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    So the $ sign is always present? Is there only one dollar amount in each paragraph? Is each paragraph in a table field?
    If yes to all, try a function that will check the string for the variations and return correct result. Something like:
    Code:
    Public Function DollarAmt(s As String) As Double
    If InStr(s, "$") Then
        s = Mid(s, InStr(s, "$") + 1)
        If Mid(s, Len(Trim(Val(s))) + 1, 1) = "k" Then
            s = Val(s) & "000"
        Else
            s = Val(Replace(s, ",", ""))
        End If
    Else
        s = 0
    End If
    DollarAmt = s
    End Function
    Then call the function in a query or textbox like: DollarAmt([fieldname])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    WSUAccess is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    3
    Yes, the $ sign is always present. Sometimes there are multiple $ signs in one paragraph, and ideally I would like the max one, but I assumed it wasn't possible. And each paragraph is in its own seperate table field.

    Thanks so much for your help. I really appreciate it.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    It is possible to find all dollar amounts in each paragraph. Just a more complex function. Need variable to hold the found amount and test it against the next found, set variable to the greater. As long as the $ presence can be depended on, keep whittling down the paragraph string with string manipulation until no more $ to be found. Set up another variable to hold the 'whittled' string. This will all involve looping structure. A condition for the loop to continue might be: Do While InStr(w,"$") > 0. Once you understand string manipulation and looping concept, simply an exercise in logic. Good one to learn on.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    WSUAccess is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    3
    I haven't quite figured out how to make it count all the $ signs, then run a DO WHILE statement. But the query does pull at least one dollar amount from each paragraph, and that is far more than I could have done on my own.

    June7, Thank you so much for your help.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You don't count the $ signs. You 'whittle' the string using string manipulation functions. Roughly, the logic is: Find a $ sign, truncate the string value up to position of $ +1, extract amount, compare amount variables, reset number and string variables, repeat in loop until no $ encountered and the maximum amount is returned.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-19-2010, 09:33 AM
  2. Replies: 4
    Last Post: 03-31-2010, 03:41 PM
  3. How do I return the maximum value
    By kam in forum Queries
    Replies: 2
    Last Post: 03-17-2010, 07:38 AM
  4. Replies: 33
    Last Post: 06-17-2009, 10:22 AM
  5. Paragraph
    By supatsiri in forum Reports
    Replies: 0
    Last Post: 02-06-2009, 10:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums