|
dhookom (Programmer) |
6 Jan 11 12:20 |
I have a couple functions in my code library that might help. The first sticks a character in your long string at user-defined lengths. CODEFunction SectionIt(strTxt As String, _ intBreakAt As Integer, _ strFindBreak As String, _ strBreakChar As String) As String Dim strReturn As String Dim strLine As String Dim intFoundAt As Integer Dim strWorkingWith As String strWorkingWith = strTxt Do Until Len(strWorkingWith) = 0 strLine = Left(strWorkingWith, intBreakAt + 1) intFoundAt = InStrRev(strLine, strFindBreak) If intFoundAt > 0 Then strReturn = strReturn & Left(strLine, intFoundAt - 1) & strBreakChar strWorkingWith = Mid(strWorkingWith, intFoundAt + 1) Else strReturn = strReturn & strLine strWorkingWith = "" End If Loop SectionIt = strReturn End Function Results of this function are: CODE?SectionIT("this is a long text string for testing", 12," ", "~") this is a~long text~string for~testing The second function can take the results of the SectionIt() function and return the number of the section you want. CODEPublic Function ParseText(pstrText As String, intElement As Integer, _ pstrDelimiter As String) As String Dim arText() As String On Error GoTo ParseText_Error
arText() = Split(pstrText, pstrDelimiter) ParseText = arText(intElement - 1) ExitParseText: On Error GoTo 0 Exit Function
ParseText_Error: Select Case Err Case 9 'subscript out of range 'don't do anything Case Else MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ParseText of Module basParseText" End Select Resume ExitParseText End Function Use these together like: CODE? ParseText(SectionIt("this is a long text string for testing", 12," ", "~"),3,"~") string for Substituting your field name and pulling the 2nd section with max of 35 characters would be: CODEParseText(SectionIt([Entity Name],35," ", "~"),2,"~") Sorry, I don't have time to re-write these to look for either a space or &. Duane Hook'D on Access MS Access MVP |
|