Get specific data out of a memo field in a table

wavp

Registered User.
Local time
Today, 15:21
Joined
Apr 18, 2003
Messages
19
I have some data in a stored in a memo field in a table, for example:

Name: Jim Smith
Email: jim@domain.com
Tel: 00012358555

Date: 23/3/02

How would I go about going making an array which will loop through each line of the data stored, so that I pick up specific data???

Thanks
 
Here's a function I wrote last week:

Code:
Public Function GetPart(ByVal strTemp As String, ByVal strDelim As String, _
    intPart As Integer) As String
    
    On Error GoTo Err_GetPart

    Dim intCounter As Integer
    Dim intTotal As Integer
    Dim intPos As Integer

    Const Message1 = "A delimiter must be a single character."
    Const Message2 = "Part exceeds delimited areas."
    Const Buttons = vbExclamation + vbOKOnly
    Const Title = "Error in Function GetPart()"
    
    If Len(strDelim) <> 1 Then
        MsgBox Message1, Buttons, Title
        Exit Function
    End If
    
    If Right(strTemp, 1) <> ";" Then strTemp = strTemp & ";"

    For intCounter = 1 To Len(strTemp)
        If Mid(strTemp, intCounter, 1) = strDelim Then
            intTotal = intTotal + 1
        End If
    Next intCounter
    
    If intPart > intTotal Then
        MsgBox Message2, Buttons, Title
        Exit Function
    End If
    
    For intCounter = 1 To intPart
        intPos = InStr(intPos + 1, strTemp, strDelim)
    Next intCounter
    
    GetPart = Mid(strTemp, intPos + 1, InStr(intPos + 1, strTemp, strDelim) - (intPos + 1))

Exit_GetPart:
    Exit Function
    
Err_GetPart:
    MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    Resume Exit_GetPart

End Function


To call it:

Code:
MyValue = GetPart(MyMemoField, vbCr, 0)

The arguments:

  • strTemp - The string to check;
  • strDelim - The delimiter;
  • intPart - The section of string split by the delimiter (starts at 0)


So, using your example where that is the text in MyMemoField using the above call will return: "Name: Jim Smith"
 
Last edited:

Users who are viewing this thread

Back
Top Bottom