|
-
Aug 12th, 2011, 11:03 AM
#1
Thread Starter
Lively Member
[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?
-
Aug 12th, 2011, 11:16 AM
#2
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.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Aug 12th, 2011, 11:28 AM
#3
Thread Starter
Lively Member
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?
-
Aug 12th, 2011, 12:12 PM
#4
Thread Starter
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|