Solved

Using an update query based on text and date

Posted on 2014-11-10
3
115 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

756 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