How Do I Search a Textbox for a String?

tkepongo

Registered User.
Local time
Today, 06:52
Joined
Jul 15, 2011
Messages
45
I need to search a textbox for a piece of string and then store that string into a variable. For example:

If the textbox value contains "Jane Doe, John Doe (Audit ID: 0337) 01/12/1991 Scheduled", then I would like to put the Audit ID "0337" into a variable.

The textbox value will always contain one Audit ID but the other values will change.

Is this even possible?

Other people have coded to split a string so I tried manipulating the code below but couldn't get the results I wanted
Code:
 Dim fullSearchString As String
Dim strWhere As String
Dim startPos As Integer

startPos = 1
fullSearchString = Me.MySearchBox.Value

strWhere = "WHERE"
For x = 0 To MaxValue
    strWhere = strWhere & " Field1 LIKE '%"
    strWhere = strWhere & Mid(fullSearchString, startPos, InStr(startPos, "Audit#:", fullSearchString))
    strWhere = strWhere & "%' AND"
    startPos = InStr(startPos, " ", fullSearchString)
Next x

strWhere = Left(strWhere, Len(strWhere) - 3) 'remove last AND

MsgBox strWhere


I also tried the code below and was able to store a variable for characters up to the numeric value but couldn't capture the numeric value
Code:
Dim i As Integer
Dim partStr As String
Dim partNum As String

For i = 1 To Len(MySearchBox)
If IsNumeric(Mid$(MySearchBox, i, 1)) Then
partStr = Left$(MySearchBox, i - 1)
partNum = Mid$(YourTextField, i)
Exit For
End If
Next
MsgBox partStr
MsgBox partNum
End Sub

Thank you all for your help!
 
Last edited:
If you want to pick up a series of four numbers that follow the first occurrence of the the string "ID: " the following should do it for you;
Code:
Mid(Me.YourTestBox, InStr(1, Me.YourTestBox, "ID: ") + 4, 4)

This relies on the string always containing the format ID: #### ie. the text ID followed by a full colon and a space, and then four numbers.
 
Last edited:
Thank you for the info !!
 

Users who are viewing this thread

Back
Top Bottom