Connecting Tech Pros Worldwide Help | Site Map

SQL delete statement -

Newbie
 
Join Date: Jul 2007
Posts: 17
#1: Jul 10 '07
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 "ComponentsSubform.ProductId" and "ComponentsSubform.SubProductId') 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's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#2: Jul 10 '07

re: SQL delete statement -


You have to get rid of the single quotes.
Expand|Select|Wrap|Line Numbers
  1. "NumberID = '" & lngID & "'"
  2. "NumberID = " & lngID
  3.  
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.
Newbie
 
Join Date: Jul 2007
Posts: 17
#3: Jul 10 '07

re: SQL delete statement -


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.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#4: Jul 10 '07

re: SQL delete statement -


Quote:

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.
Reply


Similar Microsoft Access / VBA bytes