Problem with an SQL command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • devonknows
    New Member
    • Nov 2006
    • 137

    #1

    Problem with an SQL command

    If anyone can offer any advice on this i will be most grateful,

    Ok im having trouble with an SQL Command, i have to assign the text from List2.Text into a LIKE section of my SQL statement.

    Code:
    statement = "SELECT Albumname, DIR, Mix FROM BonkersListAndDir WHERE Albumname LIKE '' ORDER BY Albumname"
    That is the statment i am using, and next to the LIKE i have tried allsorts to inset the data for example

    WHERE Albumname LIKE 'List2.Text'
    WHERE Albumname LIKE '' & List2.Text
    WHERE Albumname LIKE List2.text & ''

    but also i need to add the % wildcard at the end of List2.text, ive also tried assigning List2.text to a var,

    Code:
        Text = List2.Text & "%"
       statement = "SELECT Albumname, DIR, Mix FROM BonkersListAndDir WHERE Albumname LIKE '' ORDER BY Albumname"
    and inserting that between, before and after the '' symbols, but none of it seems to be going, al im getting is when i run it, that its an invalid SQL statement of some description, if anyone can help me, be most greatful. Thank you very much
  • devonknows
    New Member
    • Nov 2006
    • 137

    #2
    Sorry, My bad, didnt know wether that was supposed to be in the Mysql Section as it was actually mysql question lol, i just was in the Visual Basic part looking, but heres the code im working with in case any of you can help

    Private Sub List2_Click()
    If List2.ListIndex >= 0 Then
    Dim db_file As String
    Dim imagedir As String
    Dim conn As ADODB.Connectio n
    Dim rs As ADODB.Recordset
    Dim statement As String
    ' Get the data.
    db_file = App.Path
    If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
    db_file = db_file & "Data.mdb"

    ' Open a connection.
    Set conn = New ADODB.Connectio n
    conn.Connection String = _
    "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
    "Data Source=" & db_file & ";" & _
    "Persist Security Info=False"
    conn.Open
    Dim Text As String
    Text = List2.Text & "%"
    statement = "SELECT Albumname, DIR, Mix FROM BonkersListAndD ir WHERE Albumname LIKE ' ' ORDER BY Albumname"
    Set rs = conn.Execute(st atement, , adCmdText)
    Set DIRs = New Collection
    Set MIX = New Collection
    List1.Clear
    Do While Not rs.EOF
    List1.AddItem rs!MIX
    DIRs.Add CStr(rs!Dir)
    rs.MoveNext
    Loop
    rs.Close
    conn.Close
    imagedir = IMGs(List2.List Index + 1)
    Image1.Picture = LoadPicture("" & imagedir)
    Image1.Height = 1215
    Image1.Width = 1215
    End If
    End Sub

    Comment

    Working...