Hello, esteemed experts!
I have a RTF field called "TxtMedications" that contains multiple lines of text, each of these obviously preceded by a <div> tag. For example:
Lacosamide 200 mg bid
Divalproex ER 1500 mg qhs
Pregabalin 50 mg q8h
Ibuprofen 400 mg tid PRN
Cetirizine 10 mg daily PRN
Or in string form...
<div>Lacosamide 200 mg bid</div>
<div>Divalproex ER 1500 mg qhs</div>
<div>Pregabalin 50 mg q8h</div>
<div>Ibuprofen 400 mg tid PRN</div>
<div>Cetirizine 10 mg daily PRN</div>
What I'm trying to do (and where I'm currently stuck) is separating out all lines which contain the string "PRN" into another RTF text box, called "TxtPRNMeds" and having the remainder put into a RTF text box called "TxtScheduledMeds".
I'm able to use the InStr() and Mid() functions to return the first string of text between the tags and search that string for "PRN". - Dim strAllMeds As String
-
Dim strSearch As String
-
strAllMeds = Me.TxtMedications
-
-
strSearch = Mid(strAllMeds, InStr(1, strAllMeds, "<div>", vbTextCompare) + 5, InStr(1, strAllMeds, "</div>", vbTextCompare) - 6)
-
If InStr(1, strSearch, "PRN", vbTextCompare) > 0 Then
-
'Add to TxtPRNMeds
-
Else
-
'Add to TxtScheduledMeds
-
End If
So in the above, I'm able to isolate the string "Lacosamide 200 mg bid" and determine that it does not contain the matching string "PRN" but that's about as far as I've gotten to this point. Any advice on how to search the subsequent rich text lines?
Thanks for any help.
Signed,
Perplexed
I played around with the loop code a little bit, and it looks like this solved the problem: - If Len(Nz(Me.TxtMedications, "")) > 0 Then
-
GoTo SplitValues
-
Else
-
Exit Sub
-
End If
-
-
SplitValues:
-
Dim strArray() As String
-
Dim PRNBuild As String
-
Dim ScheduledBuild As String
-
Dim var As Variant
-
-
strArray() = Split(Me.TxtMedications, "</div>")
-
-
For var = LBound(strArray()) To UBound(strArray())
-
If InStr(1, strArray(var), "PRN", vbTextCompare) > 0 Then
-
PRNBuild = PRNBuild & strArray(var) & "<div> "
-
Else
-
ScheduledBuild = ScheduledBuild & strArray(var) & "<div>"
-
End If
-
Next var
-
-
-
If Len(ScheduledBuild) > 6 Then
-
TxtScheduledMeds = Left(ScheduledBuild, Len(ScheduledBuild) - 6)
-
Else
-
TxtScheduledMeds = ScheduledBuild
-
End If
-
-
If Len(PRNBuild) > 6 Then
-
TxtPRNMeds = Left(PRNBuild, Len(PRNBuild) - 6)
-
Else
-
TxtPRNMeds = PRNBuild
-
End If
Thanks for the help, Nauticalgent!!
10 1206
Dear Perplexed,
Just so I understand correctly, you have a Memo field (Long Text) that is formatted as RTF on the bound form? Also, where are the <div> tags coming from, are they imported from an external source?
Hi Perplexed...
A couple of ways to tackle this. Having never used RTF on a table or field level, I had to educate myself on the HTML tags.
I did a quick mock-up of your form and table and in my opinion the best (easiest way) to go about this would be to use the Split() function to populate and array to hold the data: - Private Sub Form_Current()
-
Dim strArray() As String
-
-
strArray() = Split(Me.TextField, "</div>")
-
-
'Debug.Print strArray(0), strArray(1)
-
' This would result in:
-
' <div>Lacosamide 200 mg bid
-
' <div>Divalproex ER 1500 mg qhs
-
End Sub
Then you could use a For Each loop to examine each Array element for the "PRN" string and act accordingly.
My first inclination would have been to use Regular expressions, but in this case, that would be using a bazooka to kill a mosquito.
That's a clever way of doing it, and sounds like it'd be the most efficient way too. For clarification on your earlier post, I have a memo field formatted in rich text that needs to be split into two textboxes formatted with rich text (TxtScheduledMeds and TxtPRNMeds). For testing and whatnot, I'm using a rich text textbox, that I'm calling TxtMedications, which holds the string needing to be split.
I've implemented your technique and tried to loop through the array elements to find matching string. - If Len(Nz(Me.TxtMedications, "")) > 0 Then
-
GoTo SplitValues
-
Else
-
Exit Sub
-
End If
-
-
SplitValues:
-
Dim strArray() As String
-
strArray() = Split(Me.TxtMedications, "</div>")
-
-
Dim PRNBuild As String
-
Dim ScheduledBuild As String
-
-
Dim element As Variant
-
For Each element In strArray
-
If InStr(1, element, "PRN", vbTextCompare) > 0 Then
-
PRNBuild = PRNBuild & element & "</div>"
-
End If
-
If InStr(1, element, "PRN", vbTextCompare) = 0 Then
-
ScheduledBuild = ScheduledBuild & element & "</div>"
-
End If
-
Next element
-
-
If Len(ScheduledBuild) > 6 Then
-
TxtScheduledMeds = Left(ScheduledBuild, Len(ScheduledBuild) - 6) 'Trim off extra "</div> string
-
Else
-
TxtScheduledMeds = ScheduledBuild
-
End If
-
-
If Len(PRNBuild) > 6 Then
-
TxtPRNMeds = Left(PRNBuild, Len(PRNBuild) - 6) 'Trim off extra "</div> string
-
Else
-
TxtPRNMeds = PRNBuild
-
End If
The code is recognizing all the array variants, but now the problem I'm running into is that it's adding each element to the PRNbuild string (even when there is no match). I can't seem to pinpoint the reason for this.
So after I run the above code, I get: TxtScheduledMeds: (Null)
TxtPRNMeds:
Lacosamide 200 mg bid
Divalproex ER 1500 mg qhs
Pregabalin 50 mg q8h
Ibuprofen 400 mg tid PRN
Cetirizine 10 mg daily PRN When I'm hoping to get: TxtScheduledMeds:
Lacosamide 200 mg bid
Divalproex ER 1500 mg qhs
Pregabalin 50 mg q8h
TxtPRNMeds:
Ibuprofen 400 mg tid PRN
Cetirizine 10 mg daily PRN Can anybody see where I'm messing this up?
I played around with the loop code a little bit, and it looks like this solved the problem: - If Len(Nz(Me.TxtMedications, "")) > 0 Then
-
GoTo SplitValues
-
Else
-
Exit Sub
-
End If
-
-
SplitValues:
-
Dim strArray() As String
-
Dim PRNBuild As String
-
Dim ScheduledBuild As String
-
Dim var As Variant
-
-
strArray() = Split(Me.TxtMedications, "</div>")
-
-
For var = LBound(strArray()) To UBound(strArray())
-
If InStr(1, strArray(var), "PRN", vbTextCompare) > 0 Then
-
PRNBuild = PRNBuild & strArray(var) & "<div> "
-
Else
-
ScheduledBuild = ScheduledBuild & strArray(var) & "<div>"
-
End If
-
Next var
-
-
-
If Len(ScheduledBuild) > 6 Then
-
TxtScheduledMeds = Left(ScheduledBuild, Len(ScheduledBuild) - 6)
-
Else
-
TxtScheduledMeds = ScheduledBuild
-
End If
-
-
If Len(PRNBuild) > 6 Then
-
TxtPRNMeds = Left(PRNBuild, Len(PRNBuild) - 6)
-
Else
-
TxtPRNMeds = PRNBuild
-
End If
Thanks for the help, Nauticalgent!!
Well done JenniferM/Perplexed, glad I could help get you pointed in the right direction...
That being said, I have to ask: I am assuming the txtMedications field holds a list of medications for a patient.
If I have that correctly then your tables are not structured correctly. You should have table with a Primary Key (PK) for the patients and another table that hold the medications for each patient. The medication table would hava a Foreign Key (FK) that would correspond to that patient's PK - each record would hold one and only one prescription which would eliminate the need for this code altogether and you could do all of this with a simple query.
What you have now is the equivalent to a multi-value field which should be avoided...
Again, this all based on the accuracy of my assumption. I am shocked some of the other members have not descended upon you like a pack of wolves.
NauticalGent:
I am shocked some of the other members have not descended upon you like a pack of wolves.
I was away for the weekend. Good catch (and advice), NauticalGent!
Speaking of Wolves...thanks TwinnyFo.
P.S. How do you quote somebody on this forum? I have not been able to figure it out. HTML tags?
Left Square Bracket Quote Right Square Bracket Left Square Bracket Highlight Right Square Bracket NauticalGent: Left Square Bracket /Highlight Right Square Bracket Carriage Return Add all y'all's text Left Square Bracket /Quote Right Square Bracket
[TwinnyFo:]
Left Square Bracket Quote Right Square Bracket Left Square Bracket Highlight Right Square Bracket NauticalGent: Left Square Bracket /Highlight Right Square Bracket Carriage Return Add all y'all's text Left Square Bracket /Quote Right Square Bracket
Wow...that is a LOT of work!
NauticalGent:
Wow...that is a LOT of work!
Not really.....
;-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: robboll |
last post by:
Using MS Access 2003 I am looking for a function that will search the
entire Tables Collection for a specific string in text or memo fields.
For example if I enter "widget" it interrogates the...
|
by: Jackson M via AccessMonster.com |
last post by:
I have buttons name A thur Z - When I select say the letter "H" button I need
my ProductName field to jump to the record that starts with the letter "H"
and soforth. Can anyone help
--
This...
|
by: John Dalberg |
last post by:
Hi
What's the regex to remove the carriage return/line field from a string?
These can occur multiple times in the string as in xxx\r\n\r\n.
--
John Dalberg
|
by: jason |
last post by:
The following vb code displays every line that has a particular string
in it. How do I list every line that does not have that string. "!"
does not seem to work for me and not sure where to place...
|
by: Pete |
last post by:
I need to create a single query (Not a SQL query) against a single
table that counts the number of records in the table, where the single
field "tmp" contains specific string values
If the field...
|
by: wayniac |
last post by:
Hello, my name is Wayne and I would like to type in a textbox so that it may search the a table in that specific field for results. But I wish for it to display all of the fields in that query.
...
|
by: AutumnsDecay |
last post by:
Hey there everyone.
I've been searching through the pages here and out on the internet, and I can honestly say I cannot find what I'm looking for.
What I'm in need of, for a client of mine, is...
|
by: bugboy |
last post by:
Hi, I need to remove the return characters from a string but i can't figure out how to reference it in a replace() method.
this.value=this.value.replace(/char(13)/, "");
Also when i test the...
|
by: David Michaels |
last post by:
I have a field called Photos in a database of information scraped from public records. This field contains the Photo information if one is available, however, if no photo is available, it inserts a...
|
by: istimac |
last post by:
General idea is to add ASCII data from text file to existing data in DataSet, first string of txt file is the same as DataSet column, but not in the same order.
I try to search one colum for...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |