Thank's, I've started incorporating this into my function and i'ts
working descent. I've decided to create a table and have the memo field
data extracted with the ID. The only issue I'm having is that, it
populated the table with the right amount of record info though only
using the first line of the memo data. Other works, if one ID has4
lines within the memo field, it repeats the data in the newly created
table with the first line of memo info 4 times.
Also, would it be possible to run this within a SQl statement for a
report and not bother with a table creation?
Her is the code:
Sub FixData()
Dim strMemotxt As String
Dim rstEquipment As Recordset ' our main table
Dim rstEquipmentLocationHistory As Recordset ' our many table
Dim mydb As Database
Dim IngEquipmentID As Long
Dim strProductName As String
Dim intMemoLines As Integer, intMemoLines2 As Integer,
intMemoLines3 As Integer
Dim strOneLine As String, strOneLine2 As String, strOneLine3 As
String
Dim I As Integer
On Error Resume Next
Set mydb = CurrentDb
Set rstEquipment = mydb.OpenRecordset("Equipment")
Set rstEquipmentLocationHistory =
mydb.OpenRecordset("EquipmentHistoryLocation")
rstEquipment.MoveFirst
Do Until rstEquipment.EOF
IngEquipmentID = rstEquipment!Abbreviation
strMemotxt = Nz(rstEquipment!USERLocationHistory, "")
intMemoLines = strDCount(strMemotxt, vbCrLf) + 1
For I = 1 To intMemoLines
strOneLine = ParseLoc(strMemotxt)
strOneLine2 = ParseFirstDate(strMemotxt)
strOneLine3 = ParseSecondDate(strMemotxt)
If strMemotxt <"" Then
rstEquipmentLocationHistory.AddNew
rstEquipmentLocationHistory!EquipmentNumber =
IngEquipmentID
rstEquipmentLocationHistory!Location = strOneLine
rstEquipmentLocationHistory!DateIn = strOneLine2
rstEquipmentLocationHistory!DateOut = strOneLine3
rstEquipmentLocationHistory.Update
End If
Next I
rstEquipment.MoveNext
Loop
rstEquipment.Close
Set rstEquipment = Nothing
rstEquipmentLocationHistory.Close
Set rstEquipmentLocationHistory = Nothing
End Sub
Public Function strDCount(mytext As String, delim As String) As Integer
Dim intPtr As Integer
Dim intFound As Integer
Dim delimLen As Integer
delimLen = Len(delim)
intPtr = InStr(mytext, delim)
Do While intPtr
intFound = intFound + 1
intPtr = intPtr + delimLen
intPtr = InStr(intPtr, mytext, delim)
Loop
strDCount = intFound
End Function
Function ParseLoc(pstrMemo As String) As String
ParseLoc = Left(pstrMemo, InStr(1, pstrMemo, vbTab & vbTab) - 1)
End Function
Function ParseFirstDate(pstrMemo As String) As String
Dim intDateStart As Integer, intDateStop As Integer
intDateStart = InStr(1, pstrMemo, vbTab & vbTab) + 2
intDateStop = InStr(intDateStart, pstrMemo, vbTab) - 1
ParseFirstDate = Mid(pstrMemo, intDateStart, intDateStop -
intDateStart + 1)
End Function
Function ParseSecondDate(pstrMemo As String) As String
Dim intTwoTab As Integer
Dim intDateStart As Integer
Dim intDateStop As Integer
intTwoTab = InStr(1, pstrMemo, vbTab & vbTab) + 2
intDateStart = InStr(intTwoTab, pstrMemo, vbTab & vbTab) + 2
intDateStop = InStr(intDateStart, pstrMemo, vbCr) - 1
ParseSecondDate = Mid(pstrMemo, intDateStart, intDateStop -
intDateStart + 1)
End Function
Any info would be appreciated,
Ron
Larry Linson wrote:
Quote:
"RMC" <Mckerral_ronald@hotmail.comwrote in message
news:1163347976.489841.322000@m7g2000cwm.googlegro ups.com...
Quote:
I though it was quitre clear, though. I stated in between the loction
and dates, they are Tabs(Tab key pressed twice) and aty the end of the
line a cariage retuern key.
>
Sorry, I overlooked the part about the Tabs.
>
The following Function procedures, if placed in a Standard Module, could be
called from within the Query you use as Record Source for your Report, or
elsewhere, if you prefer -- each stands alone, and does not rely on the
others. At the cost of reduced readability, they could be shortened somewhat
(but my preference is for readability over minimal/questionable improvement
in "efficiency").
>
Function ParseLoc(pstrMemo As String) As String
ParseLoc = Left(pstrMemo, InStr(1, pstrMemo, vbTab & vbTab) - 1)
End Function
>
Function ParseFirstDate(pstrMemo As String) As String
Dim intDateStart As Integer, intDateStop As Integer
intDateStart = InStr(1, pstrMemo, vbTab & vbTab) + 2
intDateStop = InStr(intDateStart, pstrMemo, vbTab) - 1
ParseFirstDate = Mid(pstrMemo, intDateStart, intDateStop - intDateStart +
1)
End Function
>
Function ParseSecondDate(pstrMemo As String) As String
Dim intTwoTab As Integer
Dim intDateStart As Integer
Dim intDateStop As Integer
intTwoTab = InStr(1, pstrMemo, vbTab & vbTab) + 2
intDateStart = InStr(intTwoTab, pstrMemo, vbTab & vbTab) + 2
intDateStop = InStr(intDateStart, pstrMemo, vbCr) - 1
ParseSecondDate = Mid(pstrMemo, intDateStart, intDateStop)
End Function
>
And, of course, you may wish to add some error handling.
>
Larry Linson
Microsoft Access MVP