简体   繁体   中英

MS-Access VBA code for deleting a single row based on combo box inputs

I am relatively new to access and have only done a little coding in the past so while trial and error has gotten me a ways, I have still gotten very stuck. I figured out how to create a cascading form related to inventory (research kits) but would like to code for a function that will delete just ONE row based on the combo box information (I would do a delete query, but it would delete all of the kits with the same expiration date). My form is 'Study to kit Query', table 'Inventory' first field is 'kit name' from combo box 'kit name select' then there are two others, study and expiration date. This is what has been giving me trouble:

Function Delete_Record()

DoCmd.RunSQL "DELETE * FROM Inventory
WHERE (((Inventory.[Kit Name]) = [Forms]![Study to kit Query]![Kit name select]) And ((Inventory.[Exp Date]) = [Forms]![Study to kit Query]![Expiration select]) And ((Inventory.Study) = [Forms]![Study to kit Query]![Study Select]))
LIMIT 1;"

EDIT: I have been able to get it to respond to the criteria commands, but the Limit part is still causing syntax errors.

If anyone can help fix this up, or give me direction towards something that will take those three criteria pulled from the comboboxes on a form and delete a single record in a table, I would be stoked. Thank you!

Access does not support LIMIT .
Instead you can use TOP like this:

DELETE FROM (SELECT TOP 1 * FROM Inventory
WHERE (((Inventory.[Kit Name]) = [Forms]![Study to kit Query]![Kit name select]) 
And ((Inventory.[Exp Date]) = [Forms]![Study to kit Query]![Expiration select]) 
And ((Inventory.Study) = [Forms]![Study to kit Query]![Study Select])));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM