Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Posts
    10

    Unanswered: Whats wrong with this SQL statement

    I am a newbie and I am stumped. Can someone tell me why this doesn't work?

    Private Sub cmdCustSet_Click()

    Dim sCust As String
    Dim sCustID As String
    Dim mySQL As String

    sCustID = txtCustID.Text

    With Data2
    .RecordSource = "SELECT CompanyName FROM tblCustomerInfo WHERE CustomerID = '" & sCustID & "'"
    .Refresh
    If (.Recordset.RecordCount = 1) Then
    MsgBox "good"
    Else
    MsgBox "Bad"
    End If
    End With



    End Sub

    sCustID is a number.

    Thanks for your help

  2. #2
    Join Date
    Dec 2004
    Posts
    10
    nevermind - i got it.

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    What is Data2, and where are you declaring it?

    What error or errant behavior is this giving?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    SQL Statements

    Just remember,

    If you're making your select statement criteria based on an integer or number field, use ".

    i.e. WHERE CustomerID = " & sCustID & ""

    If your making your select criteria based on a text or string field use '" (single quote, double quote.)

    If your making your select criteria based on a date field use #".

Posting Permissions

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