Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Finding each sentence until next sentence

    Hi Guy's is there a method of finding each sentence from a text box and rename each sentence ? ie:



    This is the first part of the sentence, we are hope you are staying safe.

    Thank you for taking the time to read this and your help is greatly appreciated.

    I think if we can retrieve the above 2 sentences would be great

    Once we have got these sentences broken up, then we can place which sentence we want to use elsewhere

    Thank you once again for reading this

    Look forward to your reply

    Kind Regards

    So something count how many sentences there is (there is 7 above)

    Dim a as string, b as String,c as String,d as String, e as String, f as String, g as string

    in this case a = is line 1 (Ending with safe.) b is line 2 (ending with appreciated) c = next sentence etc.....

    Note: the words at the beginning and the end of each sentence won't always be the same so i guess it may finding the NewLines and separate that way ???

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    I would use the Split() function with the "." as the parameter.

    However if you have missed a full stop in any of them, that would not work?

    If not perhaps look for uppercase letters?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I agree with Welshgasman and would adjust slightly to check for "." or vbCrLf.
    If there is a missing ".", then perhaps the "end of line" would end the sentence.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    So there will never be a line like this one? There is never 2 sentences on a line and none end in some other punctuation?
    EDIT - it may also depend on what the field format is. RTF in Access doesn't use vbCrLf as a line & paragraph marker.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    perhaps replace all the possible variations for the end of a statement with a character such as | which would not be used in a sentence. You'll need to get the order of replacement right

    something like this - you'll need to experiment since I can seen many potential variations which you may or may not consider to be end of sentence such as ?, double/triple stops (....), colons, semi colons, brackets etc
    Code:
    vText=replace(replace(replace(myText,"." & chr(13) & chr(10),"|"),".","|"),chr(13) & chr(10),"|")
    then replace all multiple | with a single |

    Code:
    while instr(vText,"||")<>0
        vText=replace(vText,"||","|")
    wend

    finally determine the number of sentences

    Code:
    SCount=ubound(split(vText,"|"))+1

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you guy's will have a play around with your suggestions

  8. #8
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by DMT Dave View Post
    Thank you guy's will have a play around with your suggestions
    Also, give a try to this:
    Code:
    Sub test()
        'Split text in sentences using regular expression.
        Dim oRE As Object
        Dim oMatches As Object
        Dim strText As String
        Dim i As Integer
    
        strText = "Sentence 1. Sentence 2? Sentence 3!!! I have to say... "
        strText = strText & "my email is: aaa@gmail.com and I have the www.aaa.com site" & vbCrLf
        strText = strText & "My name is John and I say: Good bye!"
    
        If Len(strText) Then
            'Create an object of RexExp.
            Set oRE = CreateObject("vbscript.regexp")
            With oRE
                .Global = True
                'The pattern of regular expression.
                .Pattern = "[A-Z].*?([.!?:]\s(?=[A-Z])|(?=\n)|$)"
                'Get the sentences into a collection.
                Set oMatches = .Execute(strText)
                'Print the sentences, one by one.
                For i = 0 To oMatches.Count - 1
                    Debug.Print i + 1; oMatches(i)
                Next i
                MsgBox "Your text has " & oMatches.Count & " sentences.", vbInformation, "Get sentences"
            End With
            Set oRE = Nothing
            Set oMatches = Nothing
        End If
    End Sub
    Cheers,
    John

  9. #9
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    I am hoping i explained the end goal correctly,

    in a text box called me.txtReply, is a reply to an email, i now want to grab each line (sentence) so i can set new Dims so i can use html body on reply, me.txtReply can be different words to start and/or end the line (sentence) something like:

    Good Morning

    Thank you for your email

    We are more than happy to deal with this for you

    You can book it online

    Thank you

    Dim a as String, b as String, c as String, d as String, e as String

    a = Line 1 (Good morning)
    b = Line 2 (Thank you for your email)
    c = Line 3 (We are more than happy to deal with this for you)
    d = Line 4 (You can book it online)
    e = Line 5 (Thank You)

    With this i can send a,b,c,d and e in a reply via html and should I wish to save a partucular line (letter) to the db for later use, the txtReply is split into sentences so this can allow me to save either letter

    Hope this makes sense

    Is it a case of making sure a full stop is at the end of each sentence then how anything left of that full stop is (a) then how do i say (b) is the start of next text after full stop from (a) up to the full stop in (b). etc (c), (d)

    Also if i Dim (a) through to (t), this will allow for 20 sentences, does this work ?

    please forgive me if my explanation isn't as clear as it should be but i have explained!!!!

  10. #10
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Ajax, and all others responding to this, the code that Ajax suggested POST 6 works great and returns the full message (Snipped) and the sCount = 1 so, now want i am looking for is to split each paragraph into strings, so in this case there are 11 strings so sCount needs to be 11, there could be 9 strings in the next message or 13 strings in the next message.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	36 
Size:	20.9 KB 
ID:	44500
    The 11 strings in this instance (starting lines) are:
    Thank You
    The Great
    We Offer
    Your
    We Are able
    we are currently
    If You wish
    Once Again
    we Look
    With Our
    Dave (already a string "myUser" from MainMenu login

    If a can grab each string a = sentence (thank you) b = (The Great) c = We Offer etc.... ?

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  12. #12
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    The problem that stands out to me is that you cannot use a period (.) to seperate out your strings, nor can you use a CrLf, etc. to seperate out your lines.
    If you replace the vbnewlines with a pipe(|) character you can split out the paragraphs with something like
    Code:
    Dim MyString As String
    Dim var As Variant
    Dim i As Integer
    
    
    MyString = {get your text into this variable}
    
    
    MyString = Replace(MyString, vbNewLine, "|")
    
    Debug.Print MyString
    
    var = Split(MyString, "||")
    
    
    Debug.Print "There are " & (UBound(var)+1) & " Lines"
    
    
    For i = 0 To UBound(var)
    Debug.print replace(var(i),"|"," ")                  'this returns one line
    'Debug.Print Replace(var(i), "|", vbNewLine)    'this returns the line with the original CrLf in it
    Next i
    each blank line will be replaced with 2 pipes || so you can split on those. Then replace the single pipes with spaces or vbnewlines to get your original format of the line.

    Original text
    Good morning Dave.

    Thank you for visiting www.google.com and submitting your enquiry
    for something.


    The great news is we can help.


    We do something for dealerships in the UK who
    buy repeatedly from us.


    So buy some more.


    Thanks.


    Dave.
    this will become
    Good morning Dave.||Thank you for visiting www.google.com and submitting your enquiry|for something.||The great news is we can help.||We do something for dealerships in the UK who|buy repeatedly from us.||So buy some more.||Thanks.||Dave.
    result:
    There are 7 Lines
    Good morning Dave.
    Thank you for visiting www.google.com and submitting your enquiry for something.
    The great news is we can help.
    We do something for dealerships in the UK who buy repeatedly from us.
    So buy some more.
    Thanks.
    Dave.
    If there are 2 blank lines between paragraphs/sentences, you may wind up with 3 pipes (|||) so you may have to replace ||| with || or adjust accordingly.

    EDIT: OOPs. didnt notice Ajax's post before posting.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    The problem that stands out to me is that you cannot use a period (.) to seperate out your strings,
    Thank you Mr. Moke123. That's what I said in post 4.0 Say Hi to Mrs. Moke123 for me.
    Now to split into abc lines:

    a= Thank you Mr
    b= Moke123
    c= That's what I said in post 4
    d= 0 Say Hi to Mrs
    e= Moke123 for me

    If what is wanted is boiler plate lines it might be better to concatenate a paragraph with variable. This exercise doesn't seem to be about splitting paragraphs that were received as a block of data so much as writing these paragraphs and storing them for later use as boiler plate text. Or maybe I'm wrong about that. I think this is one thread where we're all dancing around a problem without really knowing what the problem is.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I think this is one thread where we're all dancing around a problem without really knowing what the problem is.
    I agree, but it gives us something to do while we wait for OP to further clarify.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  15. #15
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you guys, will try your kind suggestions

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-22-2018, 07:47 AM
  2. Problem with Dlookup criteria sentence
    By SAM75 in forum Access
    Replies: 7
    Last Post: 12-05-2017, 12:06 PM
  3. Replies: 2
    Last Post: 08-19-2015, 06:43 PM
  4. Querying a specific text in a sentence
    By scorpion99 in forum Queries
    Replies: 1
    Last Post: 10-13-2014, 12:39 AM
  5. Replies: 2
    Last Post: 04-11-2013, 06:36 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