Results 1 to 7 of 7
  1. #1
    MarcovH is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    5

    Getting specific part out of a cell

    Hi,



    how do I extract the number of dates and number of percentages out of a cell?

    I have for example: "within 10 days 5% discount".

    In this it is always "days" and "discount". So I would expect something like 4 digits left of "days" and something like: 3 digits left of "discount".

    Preferably in basic Access as I am new to Access.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Code:
    Sub BreakupLine()
    Dim vDays, vPct
    
    
    ParseWords "within 10 days 5% discount", vDays, vPct
    MsgBox vDays, , "Days"
    MsgBox vPct, , "percent"
    End Sub
    
    
    Sub ParseWords(ByVal pvWord, ByRef pvDays, ByRef pvPct)
    pvWord = Mid(pvWord, 8)
    i = InStr(pvWord, " ")
    pvDays = Trim(Left(pvWord, i - 1))
    pvWord = Mid(pvWord, i + 5)
    i = InStr(pvWord, "%")
    pvPct = Trim(Left(pvWord, i - 1))
    End Sub

  3. #3
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Provided the string format is truly constant, this will e.g. give you the days -

    Cint(Mid(Left("within 10 days 5% discount",InStr("within 10 days 5% discount","days")-2),InStr(Left("within 10 days 5% discount",InStr("within 10 days 5% discount","days")-2)," ")))

    OR

    Cint(Mid(Left(strString,InStr(strString,"days")-2),InStr(Left(strString,InStr(strString,"days")-2)," ")))

  4. #4
    MarcovH is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    5
    thanks knarfreppep, now I tried to copy over the 2nd solution and tried to convert it to the "5" in 5%, but no joy...

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why no joy - error message, wrong results, nothing happens? Post the attempted expression.
    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.

  6. #6
    MarcovH is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    5
    sorry, but here you:
    data: within 10 days 5 % discount
    qry: Mid(Left([PaymentSettlement],InStr([PaymentSettlement],"%")-2),InStr(Left([PaymentSettlement],InStr([PaymentSettlement],"%")+2),"s"))
    outcome: S 5

    so at least I have overcome my #error, now I need to kick out the "s" in my outcome "s 5"

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why do you have an 's' in the expression?

    Try:
    Val(Mid([PaymentSettlement], InStr([PaymentSettlement], "days") + 5))

    Be aware these expressions will error if the field is null. If that is a possibility, handle nulls.

    Val(Mid(Nz([PaymentSettlement], ""), InStr(Nz([PaymentSettlement], ""), "days") + 5))
    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: 1
    Last Post: 11-20-2014, 08:34 AM
  2. Replies: 6
    Last Post: 09-10-2013, 08:37 AM
  3. import specific cell from excel to access
    By maneuk in forum Import/Export Data
    Replies: 10
    Last Post: 07-01-2011, 06:24 AM
  4. Export a value to specific Excel cell
    By gg80 in forum Import/Export Data
    Replies: 5
    Last Post: 07-23-2010, 01:58 PM
  5. Hyperlink to a specific Field/Cell?
    By tbutters in forum Database Design
    Replies: 8
    Last Post: 06-04-2010, 12:27 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