SQL delete statement -

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • atrottier
    New Member
    • Jul 2007
    • 17

    SQL delete statement -

    I'am new here so I'd like to say hello and this seems to be a great site it has already helped me a few times. I just got an assignment to correct and modify a simple access application. First some background info:. I added a delete button on a subform to remove an item from that forms list. The subfrom is populated from a table that has a primary key composed of two number fields. I have assigned varaibles to the column values for the selected row. Then with a a sql delete statement i would like to delete that row from the table. This is the delete statement:
    strSQL = " DELETE * FROM [Assembly Breakdown] " & _
    " WHERE ([ProductId] = '" & Itemident1 & "')" & _
    " AND ([SubProductId] = '" & Itemident2 & "')" & _
    " AND [SubProductName] = '" & ProductName & "' " & _
    " AND [SubPartNumber] = '" & ProductNumber & "' " & _
    " AND [SubLECNumber] = '" & LECNumber & "' ;"
    DoCmd.RunSQL strSQL
    Itemident1 and Itemident2 are the two number fields that represent the key on the table. I get a type mismatch error when the code is executed. This makes sense since the two varaibles are enclosed in quotes. No matter what I do as far as screwing with the syntax around these two variables I can't get the delete statement to recognize Itemident1 and Itemident2 as enumerated data types(long).
    I even tried to use their test box names from the subform (i.e "ComponentsSubf orm.ProductId" and "ComponentsSubf orm.SubProductI d') to no avail. Of course I haven't found any reference that states that this is even doable. Any help or insight would be greatly appreciated. Once again this is a great forum.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You have to get rid of the single quotes.
    Code:
    "NumberID = '" & lngID & "'"
    "NumberID = " & lngID
    1. This will see lngID as text no matter what lngID is and it will assume NumberID is text.
    2. The opposite is true for this one.

    Comment

    • atrottier
      New Member
      • Jul 2007
      • 17

      #3
      Thanks Rabbit, I could have sworn I tried that at least once with all the attempts at changing the statement around. I guess I couldn't see the forest because of the trees! Thanks again.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Originally posted by atrottier
        Thanks Rabbit, I could have sworn I tried that at least once with all the attempts at changing the statement around. I guess I couldn't see the forest because of the trees! Thanks again.
        Not a problem, good luck.

        Comment

        Working...