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  
  •  Windows XP trouble after attempting to Unistall HP OfficeJet G55 printer software.
  •  How do I prevent server from locking?
  •  Will google index pages that are not linked within my website?
  •  Need AJAX - Java - Slide Bar to define MIN and MAX Price Range for Product Listing
  •  Run-time Error 1004 Application-defined or object-defined error with Paste, Special, Values operation
  •  How to setup NAC Agent to be running at system startup and as a service, not as an application?
  •  PPTP connection to sonicwall cannot reach secondary site to site tunnel on same firewall
  •  Exchange 2003 Server Mail/ Spam issues
  •  Computer takes 30 minutes to boot; after (I think) an automatic update.  I had this problem no another computer a few years ago but I forgot the fix.
  •  Explorer can't find network PC but Remote Desktop/ping can
  •  
    programming4us programming4us