Use a form to delete a record

ARW17

Board Regular
Joined
Oct 31, 2016
Messages
109
I’m trying to give users the option to delete a personal day that they have scheduled. I figured out how to have them add a day, but deleting one seems more difficult…

What I want is to say in the AttendanceEvents table, delete the record where the EventDate field = date in the text box on the form, the USRI field = the USRI text box on the form, and the EventCode = “P”.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Here is a high-level view of one way of doing this.

First, create a sample query that does this for one person.
Then, change your query to SQL View, and copy and paste this code somewhere for future reference.
This is the SQL code you want to create via VBA.
So, I would then have your form create the SQL code you need via VBA, and then run that SQL code from VBA to delete your data.
 
Upvote 0
The sql statement is much like you described it. Try this on a backup copy of your table and note that if more than one line in that table could satisfy the criteria, you would lose more than one record. You could create this in vba on the form or call a query based on the statement as long as the form is open when you do so. Of course, you have to provide your own names for the form and its controls, and I'm assuming EventCode is a field in the same table.
Code:
DELETE * FROM AttendanceEvents WHERE AttendanceEvents.EventDate = Forms!frmMyForm.txtEventDate AND AttendanceEvents.USRI = Forms!frmMyForm.txtUSRI AND AttendanceEvents.EventCode = "P";
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,771
Messages
6,161,847
Members
451,723
Latest member
Rachetsely

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top