Results 1 to 2 of 2
  1. #1
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72

    Passing Criteria to IN statement from Form

    Good afternoon.

    I have a form (selector) on which there is a multiselect list box (techselect). A command button takes the selections highlighted in the list box, and concatenates them for use in a query. The query's CRITERIA is set up as follows, to receive those selections:
    In ([forms]![selector]![resultsfromtechchoices])

    The code that creates the concatenated string is at the bottom of this posting.

    The odd thing is that if I choose one item from the listbox, it works fine. If I choose two, the string is concatenated properly, but the query returns no records. If I cut the results from the text box, and paste them into the query criteria directly, it works properly. Therefore I feel I'm certain the concatenation is being done properly.

    I have tried every combination of single quotes, double quotes, spacing, commas, yaddah yaddah.

    Any thoughts would be greatly appreciated.

    Stephen.
    Total newbie. This is my first attempt at any code, so don't slap me too hard!

    ---------------
    Private Sub Command2_Click()
    Dim varitem As Variant
    Dim strcriteria As String
    Dim strSQL As String
    For Each varitem In Me!Techselect.ItemsSelected
    strcriteria = strcriteria & Me!Techselect.ItemData(varitem) & ", "
    Next varitem

    If Len(strcriteria) = 0 Then
    MsgBox "you did not select anything from the list of technicians", vbExclamation, "Nothing to find!"
    Exit Sub

    End If
    strSQL = left(strcriteria, Len(strcriteria) - 2)

    If Len(strSQL) > 0 Then
    strSQL = left(strSQL, Len(strSQL))


    Me.ResultsFromTechChoices.Value = strSQL
    Else
    Me.ResultsFromTechChoices = Null
    End If

    End Sub

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Wat does your strSQL look like if you do a debug.print strSQL

    What type of data is it?
    are there any spaces?
    You don't seem to be wrapping them in quotes

    Also, and more importantly you seem to have missed out the all important IN() clause

    strSQL = "In(" & strSQL & ")"

    also

    strSQL = left(strSQL, Len(strSQL))

    is doing nothing

    David

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing data to sequential form fields
    By jeepfamilyva in forum Forms
    Replies: 0
    Last Post: 06-28-2009, 11:04 AM
  2. nested if statement with two criteria
    By kendra in forum Queries
    Replies: 5
    Last Post: 06-16-2009, 04:07 PM
  3. Replies: 3
    Last Post: 06-02-2009, 09:51 AM
  4. Passing a variable to a form
    By cjamps in forum Forms
    Replies: 0
    Last Post: 03-02-2009, 05:32 AM
  5. Open form based on Subform criteria
    By Suzan in forum Programming
    Replies: 0
    Last Post: 04-25-2006, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums