Results 1 to 4 of 4

Thread: [RESOLVED] String Search with Spaces

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    65

    Resolved [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?

  2. #2
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    65

    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?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    65

    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
  •  



Click Here to Expand Forum to Full Width