Question : delete a record using VBA.

I want to delete a record based on a selection from a combobox.
my combobox is called cboFormRef.
I have seven tables.
The main table is called tbl_StaffSurveyMain.
contains the following fields SurveyKey autonumber. Store Text PK. FormRef PK.
My other tables are as follows.
SectionOne Autonumber. Store PK. FormRef PK. QuestionOne-QuestionFour Number.

So when the user selects a formref from the dropdown list i want that record to be deleted.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
My select statement looks like the followimg. This is just an idea to give you an example of the tables i am using.
 
    'SELECT tbl_StaffSurveyMain.*, tbl_SectionOne.*, tbl_SectionTwo.*, tbl_SectionThree.*, tbl_SectionFour.*, tbl_SectionFive.*, tbl_SectionSix.*
    'FROM (((((tbl_StaffSurveyMain INNER JOIN tbl_SectionOne
        'ON tbl_StaffSurveyMain.FormRef = tbl_SectionOne.FormRef)
        'INNER JOIN tbl_SectionTwo ON tbl_StaffSurveyMain.FormRef = tbl_SectionTwo.FormRef)
        'INNER JOIN tbl_SectionThree ON tbl_StaffSurveyMain.FormRef = tbl_SectionThree.FormRef)
        'INNER JOIN tbl_SectionFour ON tbl_StaffSurveyMain.FormRef = tbl_SectionFour.FormRef)
        'INNER JOIN tbl_SectionFive ON tbl_StaffSurveyMain.FormRef = tbl_SectionFive.FormRef)
        'INNER JOIN tbl_SectionSix ON tbl_StaffSurveyMain.FormRef = tbl_SectionSix.FormRef;
Open in New Window Select All

Answer : delete a record using VBA.



In the combo afterupdate event procedure..change the code to use your own combo and field names

if isnull(me.comboboxname) then exit sub
if  msgbox ("This will delete the records that match the selected value , OK?" , vbyesno+vbquestion, "Delete records") = vbno then exit sub
currentdb.execute "Delete * from [one-six] where fieldname = '" & me.comboname & "'", dbfailonerror
Random Solutions  
 
programming4us programming4us