what's wrong with this sql?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • allj
    New Member
    • Sep 2007
    • 23

    what's wrong with this sql?

    I was using this for a multiselect frm with two listboxes on each side where I was able to update the selected field in one to place it in the other lstbox and then open the appropriate form by whether selected field is yes. I have been using this successfully until now. The field "insurance" is in the "insurance" table and is the primary key. I get a missing operator message.
    Dim db As Database, rs As Recordset, sql As String
    Dim L As Control
    Set L = Me![lstinsurance] 'the name of the unbound lstbox
    Set db = CurrentDb
    sql = "SELECT [Selected],[insurance].[insurance] FROM [insurance] where [insurance].[insurance] = " & L
    Set rs = db.OpenRecordse t(sql, DB_OPEN_DYNASET )
    rs.Edit
    rs("selected") = True
    rs.Update
    rs.Close
    Me.Recalc
    thanks for any help with this. alan
  • Jim Doherty
    Recognized Expert Contributor
    • Aug 2007
    • 897

    #2
    Originally posted by allj
    I was using this for a multiselect frm with two listboxes on each side where I was able to update the selected field in one to place it in the other lstbox and then open the appropriate form by whether selected field is yes. I have been using this successfully until now. The field "insurance" is in the "insurance" table and is the primary key. I get a missing operator message.
    Dim db As Database, rs As Recordset, sql As String
    Dim L As Control
    Set L = Me![lstinsurance] 'the name of the unbound lstbox
    Set db = CurrentDb
    sql = "SELECT [Selected],[insurance].[insurance] FROM [insurance] where [insurance].[insurance] = " & L
    Set rs = db.OpenRecordse t(sql, DB_OPEN_DYNASET )
    rs.Edit
    rs("selected") = True
    rs.Update
    rs.Close
    Me.Recalc
    thanks for any help with this. alan
    Hi Allj,

    Amend your sql to place a quote either side of the value of L

    Code:
     
    sql = "SELECT [Selected],[insurance].[insurance] FROM [insurance] where [insurance].[insurance] [b]= '" & L & "'"[/b]
    Please remember to use code tags when posting code

    Regards

    Jim :)

    Comment

    • allj
      New Member
      • Sep 2007
      • 23

      #3
      thank you. Much appreciated.

      Comment

      • Jim Doherty
        Recognized Expert Contributor
        • Aug 2007
        • 897

        #4
        Originally posted by allj
        thank you. Much appreciated.
        You're welcome :)

        Jim

        Comment

        Working...