Results 1 to 4 of 4

Thread: SQL....to few parameters!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Location
    na
    Posts
    26

    SQL....to few parameters!

    Private Sub GetContactInfo()
    Dim SQL As String
    SQL = "SELECT * From tblTeams WHERE [fldTeamName] = lstteamNames.Text"

    Set rs = db.OpenRecordset(SQL) 'this is the highlighted error line
    If rs Is Nothing Then Exit Sub
    rs.MoveLast
    rs.MoveFirst
    While Not rs.EOF
    txtHCName.Text = rs("fldHCName") & ""
    txtHCPhone.Text = rs("fldHCPhone") & ""
    rs.MoveNext
    Wend


    End Sub

    If anyone knows a decent site to learn more about SQL...please let me know.

  2. #2
    Addicted Member jestes's Avatar
    Join Date
    Jan 2001
    Location
    Dallas
    Posts
    248

    here

    SQL = "SELECT * From tblTeams WHERE [fldTeamName] = '" & lstteamNames.Text & "' "

    when using a variable in an SQL statement, you must use ' then " before (and after) concatenating the variable into the string. If this still doesn't work, verify that you've spelled the columns correctly.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Location
    na
    Posts
    26

    Smile

    Wow...it worked!
    I couldn't find very much in the MSDN on this...unless I am just looking in the wrong area. But where can you recommend for me to learn more about this. I am not sure what the "&" are even for when used that way. My project is going to be full of changing sql's and recordset's. Thanks again for the help

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    basically the &'s concatenate the string together so:

    VB Code:
    1. dim strA as String
    2. dim strB as string
    3. strA="DOG"
    4. strB = strA & "Cat"

    strB now contains "DOGCat"

    That is basically what jestes example is doing. It is taking strings and adding them together. It is adding the beginning of your SQL, then your text box value, and then it is finishing off your SQL statement.

    Hope this helps,

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