Results 1 to 3 of 3
  1. #1
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Multi-select code help

    Hi All!

    I "highjacked" the following code (amended) from another app. so I'm not sure how it works, but I'm getting a "Compile Error: For without Next". Little help?
    <pre>Private Sub cmdSearch_Click()
    Dim i As Long
    Dim strWhereTotal As String
    Dim strWhereCategory As String
    Dim strWhereType As String
    Dim strWhereSource As String

    On Error GoTo ErrHandler

    If lstCategory.ItemsSelected.Count = 0 Then
    MsgBox "You must select at least one Category", vbExclamation
    Exit Sub
    End If

    If lstType.ItemsSelected.Count = 0 Then
    MsgBox "You must select at least one Type", vbExclamation
    Exit Sub
    End If

    If lstSource.ItemsSelected.Count = 0 Then
    MsgBox "You must select at least one Source", vbExclamation
    Exit Sub
    End If

    For i = 0 To lstCategory.ListCount - 1
    If lstCategory.Selected(i) = True Then
    strCategory = strCategory & ", " & Chr(34) & lstCategory.ItemData(i) & Chr(34)
    End If
    Next i

    For i = 0 To lstType.ListCount - 1
    If lstType.Selected(i) = True Then
    strType = strType & ", " & Chr(34) & lstType.ItemData(i) & Chr(34)
    End If
    Next i

    For i = 0 To lstSource.ListCount - 1
    If lstSource.Selected(i) = True Then
    strSource = strSource & ", " & Chr(34) & lstSource.ItemData(i) & Chr(34)
    End If

    strWhereCategory = "[Category] IN (" & Mid(strCategory, 3) & ")"
    strWhereType = "[Type] IN (" & Mid(strType, 3) & ")"
    strWhereSource = "[Source] IN (" & Mid(strSource, 3) & ")"
    strWhereTotal = strWhereCategory & " And " & strWhereType & " And " & strWhereSource

    DoCmd.OpenForm "frmRecipeSearchResults", acNormal, , strWhereTotal
    Exit Sub

    ErrHandler:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If

    End Sub</pre>



    Any and all help greatly appreciated!
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  2. #2
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multi-select code help

    after a quick look this jumps out:

    <font face="Georgia">For i = 0 To lstSource.ListCount - 1
    If lstSource.Selected(i) = True Then
    strSource = strSource & ", " & Chr(34) & lstSource.ItemData(i) & Chr(34)
    End If </font face=georgia>

    In the code blocks above <font face="Georgia">Next i</font face=georgia> follows but not in this one. Put that in and see what happens.

  3. #3
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Multi-select code help

    Steve:
    <img src=/S/bullseye.gif border=0 alt=bullseye width=45 height=15>
    Thanks pal. . .you nailed it!
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •