Results 1 to 9 of 9

Thread: SQL Query

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    43
    New problem. I am changing a program to ADO. The following query worked before

    "SELECT * FROM qryListCustomers WHERE LastName LIKE '" & txtFind.Text & "*" & "'"

    to filter the records by the first letter, or first 2... But know that I have switched over to ADO, it will not. I can just put qryListCustomers after the recordset open statement, and get all the records, but if I try using this SQL statement, I get zero records.

    Any ideas? I do not know much SQL, still learning
    Tim

    VB6, SP4
    GT Vengeance

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Don't use qryListCustomers. The SELECT statement works with tables only. If you make a composite query that does the work of both, then that'll work.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    43
    The SELECT statement worked with qryListCustomers before I started swapping the program over to ADO. Why won't it work now.

    Composite query?
    Tim

    VB6, SP4
    GT Vengeance

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If qryListCustomers has already been executed, then it will have a recordset. If it hasn't, then there will be no data for it. This is why it is best to extract data direct from the table. Also, ADO works differently to DAO, so they will both have different ideas about where the data comes from. DAO was almost specifically for Jet, so it may know to execute the query first.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Have you tried changing the '*' to '%'. Wildcards changed from DAO to ADO...

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Also, try using single rather than double quotes. Don't ask me why (because I don't know ), but sometimes it helps.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    43
    Thanks for your suggestions. The % wildcard is giving me runtime errors, and going to single quotation marks makes the program not able to find the database.

    I am using this query to populate a listview. With the statement the way it is, but getting rid of the Like, I can get the full listing using either qryListCustomers, or from a table. Using the Like, I am still getting the correct columnheaders, but no data, for both a query and a table. Unfortunatly I need the like to filter the records. It seems like the Like is filtering all the records. Similar to the way my coffee filter evidently filtered all my caffeine this morning.

    Any other ideas?

    Thanks
    Tim

    VB6, SP4
    GT Vengeance

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    43
    Ah ha!

    I kept fooling around and this worked:

    rsListData.Open "SELECT * FROM qryListCustomers WHERE LastName LIKE '" & txtFind.Text & "%" & "'", _
    dbPrimary


    * for the first part and % for the second.

    Thanks for all your help! I would be interested in knowing why it worked this way! I learned something, I just do not know what!

    Tim

    VB6, SP4
    GT Vengeance

  9. #9
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    You learned that 'select *' means select all columns from a table and that 'LIKE "BA*"' means everything starting with BA and one more letter and that 'LIKE "BA%"' means everything starting with BA.

    Just like JHausmann said, DAO and AOD changed wildcards.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

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