Results 1 to 8 of 8
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365

    Find : InStr And Add Date

    Hi Guys, i am trying to use the replace function to find the Colon,

    Keep everything before it, Add the date in my case NewWC then 2 line breaks then everything after that

    So it should be something like

    Good Morning all you guys the forum

    We can offer you week commencing: (NewWC Goes Here)

    If this works of for you

    Please confirm this etc etc....

    I think my sequence in the replace function wrong ????

    I won't put the full code as its quite large
    myrow is select case


    NewText is String, NewWC is String, myLine is string "........."

    Code:
     Me.txtAddLine = DLookup("TextToAdd", "tblAddLine", "[ID] = " & myRow)
        NewText = Me.txtAddLine
        Me.txtReply = myGreet & vbNewLine & vbNewLine & _
        NewText & vbNewLine & vbNewLine & myLine & vbNewLine & vbNewLine & Me.txtMailMessage
        NewWC = Format(Me.txtFrom, "dddd-dd-mmm-yyyy")
        myStr = Replace(NewText, ":", ": " & NewWC & vbNewLine & vbNewLine & myLine & vbNewLine & vbNewLine & Me.txtMailMessage)

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Looks fine to me. But since I don't know what each variable is actually populated with, can't be sure.

    What is the resulting string in myStr? If you don't like the result, then change the sequence.
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Why can't you just do a simple replace.
    Place a marker like "InsertDate" in your text block and replace InsertDate with your formatted date?
    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

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Hi welshgasman thank you, will try playing around with it, can't harm anything

    Just didn't know if anything obvious like me not getting sequence correct in replace function

    Its one of those where it should be easy to find anything before and after colon then add after the colon and resume with what was already after colon prior to date going in

    abcdef:

    ghijklm

    to become

    abcdef: 14-August-2021

    ghijklm

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I would not even bother searching for colon.
    Just put something in as a place marker, that could not possibly exist in normal usage, and then just replace that with your date.?

    What if you have several colons in there like one of my emails?
    Code:
    From Donor: RBL
    Received: 02/09/2020
    Method: BACS
    Reference: APBACS/108525
    Amount: £558.00
    Balance: £1,058.00
    Notes: Courtesy notification only
    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

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    very true, there would every be only 1 colon though as its from a table of replies

    however, your suggestion worked great but still loose text after "InsertDate"

    So now my line says : InsertDate and now replaces with date, works great thank you very much wgm

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by DMT Dave View Post
    very true, there would every be only 1 colon though as its from a table of replies

    however, your suggestion worked great but still loose text after "InsertDate"

    So now my line says : InsertDate and now replaces with date, works great thank you very much wgm
    How can you lose text after InsertDate? with a simple Replace?

    Show your replace statement.
    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

  8. #8
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Hi wgm, I have corrected it, just had an override after the event so moved the override of code,

    just couldn't see the wood for the trees, but what a simple way to replace what you have suggested particularly when the keyword to replace is from your table then it's always the same word to replace!

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

Similar Threads

  1. VBA InStr find text and import space
    By luckydead in forum Programming
    Replies: 4
    Last Post: 11-03-2020, 01:06 PM
  2. Replies: 2
    Last Post: 04-07-2016, 07:19 AM
  3. Replies: 3
    Last Post: 08-24-2015, 03:30 PM
  4. Replies: 2
    Last Post: 07-09-2013, 06:31 PM
  5. IIF with instr
    By yoili in forum Reports
    Replies: 2
    Last Post: 01-22-2013, 01:32 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