[RESOLVED] String Search with Spaces
Hey Everyone,
I'm searching a table for the string
"Top Box".
The record in my table is
"1/2 Top Box"
However, when I loop through the records in my table it doesn't find the record. Here's my code.
Code:
ElseIf InStr(UCase(Box), UCase("Top Box")) > 0 Then
WhiteText = QOH
MsgBox Box
And ideas how I should go about searching for the string?
Re: String Search with Spaces
Make sure your code is reaching the statement and that Box variable has the record value. The code as it stands is good and should work. Use a breakpoint and watch the value of Box at that point.
Re: String Search with Spaces
Thanks for the reply Kaliman.
This is my full code.
Code:
Dim Colors As Recordset
Set dabs = CurrentDb
Set Colors = dabs.OpenRecordset("DPBoxesTrays")
With Colors
.MoveFirst
Do Until .EOF
Box = !Supply
QOH = !QOH
If InStr(UCase(Box), UCase("Planting Box")) > 0 Then
RedText = QOH
ElseIf InStr(UCase(Box), UCase("Lid")) > 0 Then
BlueText = QOH
ElseIf InStr(UCase(Box), UCase("Top")) > 0 Then
YellowText = QOH
ElseIf InStr(UCase(Box), UCase("Bottom")) > 0 Then
PinkText = QOH
ElseIf InStr(UCase(Box), UCase("Spaces")) > 0 Then
PurpleText = QOH
ElseIf InStr(UCase(Box), UCase("Top Bottom")) > 0 Then
PlaiText = QOH
ElseIf InStr(UCase(Box), UCase("Top Box")) > 0 Then
WhiteText = QOH
ElseIf InStr(UCase(Box), UCase("Coin")) > 0 Then
BlackText = QOH
ElseIf InStr(UCase(Box), UCase("Ear")) > 0 Then
EarText = QOH
ElseIf InStr(UCase(Box), UCase("Large")) > 0 Then
LargeText = QOH
End If
.MoveNext
Loop
End With
Me.Repaint
The first "Planting Box" works, however, "Top Bottom" and "Top Box" Do not display anything. Is it because my record has integers in it?
Re: String Search with Spaces
I found my very simple, yet very trouble some mistake.
My code was reading some of the strings as the same which was correct. I just had the same words in a few of my records.
Thanks for letting me know it was right though, it led me in the correct direction!
Code:
Dim Colors As Recordset
Set dabs = CurrentDb
Set Colors = dabs.OpenRecordset("DPBoxesTrays")
With Colors
.MoveFirst
Do Until .EOF
Box = !Supply
QOH = !QOH
If InStr(UCase(Box), UCase("Planting Box")) > 0 Then
RedText = QOH
ElseIf InStr(UCase(Box), UCase("Lid")) > 0 Then
BlueText = QOH
ElseIf InStr(UCase(Box), UCase("Top")) = 1 Then
YellowText = QOH
ElseIf InStr(UCase(Box), UCase("Bottom")) = 1 Then
PinkText = QOH
ElseIf InStr(UCase(Box), UCase("Spaces")) > 0 Then
PurpleText = QOH
ElseIf InStr(UCase(Box), UCase("Top Box")) > 1 Then
PlaiText = QOH
ElseIf InStr(UCase(Box), UCase("Bottom Box")) > 1 Then
ShootText = QOH
ElseIf InStr(UCase(Box), UCase("Coin")) > 0 Then
BlackText = QOH
ElseIf InStr(UCase(Box), UCase("Ear")) > 0 Then
EarText = QOH
ElseIf InStr(UCase(Box), UCase("Large")) > 0 Then
LargeText = QOH
End If
.MoveNext
Loop
End With
Me.Repaint