Results 1 to 5 of 5
  1. #1
    KylieReed is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2014
    Posts
    4

    Get values from a text box into a query

    Hi,
    I have a query that I would like run by getting multiple values from a list box. I use a for loop to get the values and put them in a text box, which the query then refers to.
    The problem is when I manually type the values from the text box into the query, the query runs fine but it won't run when its referring to the same values in the in the text box even though they are the same.

    Any help is appreciated.

    If CheckifRowisSelected = True Then
    For intCurrentRow = 0 To Me.listbox.ListCount - 1
    If lstTerm.Selected(intCurrentRow) = True Then 'Check if the row is selected
    QueryValues= Me.listbox.Column(0, intCurrentRow) & " or "
    End If
    Next
    If Len(QueryValues > 0 Then
    Me.textbox = Left(QueryValues, Len(QueryValues) - 4)
    End If
    End If



    Many thanks

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    What is the SQL rendered by Access?
    Do a Debug.print me.textbox and/or Debug.print QueryValues to see what Access thinks these values are.

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    And the data types. Access query design will add quotes or date delimiters (#) automatically, but VB won't. You have to concatenate delimiters manually.

  4. #4
    KylieReed is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2014
    Posts
    4
    Thank you. The data type is integer and the values I'm trying to get to work have an or between them. ie 1 or 2 or 3. I have concatenated the delimiters for the for the integers but it doesn't like the or. Is there something I need to do to this too?

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    you didn't follow the suggestion of orange in post #2...

    I have concatenated the delimiters for the for the integers
    I dont' follow (maybe because you didn't post as requested). Numbers don't need delimiters.

    My guess: swap " or " for "," and change Left(QueryValues, Len(QueryValues) - 4) to "IN(" & Left(QueryValues, Len(QueryValues) - 1) & ")" including all quotation marks. I assume you're referencing this form control value in a query WHERE clause.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-09-2014, 12:43 PM
  2. Crosstab Query Values Export as Text
    By Paul H in forum Queries
    Replies: 0
    Last Post: 01-07-2013, 11:18 AM
  3. Replies: 1
    Last Post: 12-15-2011, 04:44 AM
  4. Replies: 10
    Last Post: 07-02-2011, 11:51 AM
  5. Displaying multiple text values in crosstab query
    By MFlood7356 in forum Queries
    Replies: 6
    Last Post: 06-28-2011, 11:30 AM

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