Solved

Using an update query based on text and date

Posted on 2014-11-10
3
117 Views
Last Modified: 2014-11-10
I have a memo field that might have the following text (mixed in with other text):

PT Notified of DS office
PT Notified of DS office (MM-DD-YY)
PT Notified of DS office (MM/DD/YY)

I would like to remove this from the memo field.  I have found a way to do so for the text portion but not the date portion.  (Replace [Notes],"*PT Notified of DS office*,"")

Is it possible to something like this and then trim the results when there is a date?
0
Comment
Question by:thandel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 40434292
You could run two different queries, one without a trailing date and the other with a trailing date.  You would need to run the WITH DATE query first.

The first query's Where clause would be:
Where Notes like "*PT Notified of DS office (##-##-##)*"
OR Notes like "*PT Notified of DS office (##/##/##)*"

A simplified version of the Where clause might be:
Where Notes like "*PT Notified of DS office (##[/-]##[/-]##)*"
or
Where Notes like "*PT Notified of DS office (##[-/]##[-/]##)*"

The actual update would need to use the Instr() and Mid() functions and maybe the Left() function.  It gets messy.

I think you have a problem with your Replace() function.  It should be:
Set [Notes] = Replace([Notes],"PT Notified of DS office", "")

Open in new window


It seemed easier to write a function to do the replace:
Option Explicit

Public Function Q_28554797(ByVal parmNote As String, ByVal parmPattern As String, ByVal parmReplacePattern As String) As String
    Static oRE As Object
    Static strPattern As String
    
    If oRE Is Nothing Then
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
        oRE.Pattern = parmPattern
        strPattern = parmPattern
    End If
    
    If strPattern = parmPattern Then
    Else
        oRE.Pattern = parmPattern
        strPattern = parmPattern
    End If
    
    If oRE.test(parmNote) Then
        Q_28554797 = oRE.Replace(parmNote, parmReplacePattern)
    Else
        Q_28554797 = parmNote
    End If
    
End Function

Open in new window


This is how you would use it in an update query.
Set Notes = Q_28554797(notes,"PT Notified of DS office \(\d\d(?:-|/)\d\d(?:-|/)\d\d\) ?", "")

Open in new window

0
 

Author Comment

by:thandel
ID: 40434305
I made this into an SQL query but doesn't replace the desired text.  Can I not implement it in this manner?

UPDATE TPatient SET TPatient.Notes = Replace([notes],"PT Notified of DS office \(\d\d(?:-|/)\d\d(?:-|/)\d\d\) ?","")
WHERE (((TPatient.Notes) Like "*PT Notified of DS office*"));
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40434311
You can't use regular expression patterns with the Access/VB Replace() function.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question