Results 1 to 2 of 2

Thread: SQL Statement Question (VB6)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    SQL Statement Question (VB6)

    Hello,

    I have an SQL question. I am using VB6 in an app, and want to use the ADODC control to search my data (which is an Excel 2000 file).

    The SQL statement I am trying to do would search fields called Product #1, Product #2, and Product #3. I was trying the following code, but it is not working.

    Private Sub Command1_Click()
    Adodc1.RecordSource = "Select * from [Sheet1$] Where [Product #1] = "Widget (CD) And [Product #2] = "Widget (CD) And [Product #3] = "Widget (CD)"
    Adodc1.Refresh
    End Sub

    Any ideas or SQL tutorial links would be appreciated. Thank you!

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL Statement Question (VB6)

    Moved to Database Development forum

    You need to use single quotes around text values, instead of double quotes as you have, eg:
    VB Code:
    1. Adodc1.RecordSource = "Select * from [Sheet1$] Where [Product #1] = [b][u]'[/u][/b][u][/u]Widget (CD)[b][u]'[/u][/b][u][/u] And [Product #2] = [b][u]'[/u][/b][u][/u]Widget (CD)[b][u]'[/u][/b][u][/u] And [Product #3] = [b][u]'[/u][/b][u][/u]Widget (CD)[b][u]'[/u][/b][u][/u]"

    As for tutorials, see the FAQ's at the top of this forum - I'd specifically advise reading the article about why bound controls are bad.

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