Solved

Using an update query based on text and date

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now