Connecting Tech Pros Worldwide Forums | Help | Site Map

Using a list box to select a record to delete

Member
 
Join Date: Mar 2007
Posts: 66
#1: Apr 25 '07
Hi,

A section of my database allows users to delete items from a table, there is only one collumn in the table, this contains module information(parts of a manufacturing line) due to the lines regulary changing i added a section to delete modules. so far ive got the combo box which selects the modules from a table using a select query, when a specific module is selected i need it to be deleted.

the problem im having is when the delete button is pressed it deletes the top item in the table not the one selected.

i tried resolving this so when the list box item is clicked whatever module has been selected gets put into an invisible text box on the form, and when the delete button is pressed it is supposed to delete whatever is in the text box but i am getting the same problem (deletes first item in table not the one selected)

here is the code that is used on the deleted button and combo box:
--------------------------------------------------------------------------------------------------
Private Sub cmddel_Click()
'Yes/No opetion box
RetValue = MsgBox("Are you sure you want to delete this module", vbOKCancel)

'if the value equals yes then module is deleted
If RetValue = 1 Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
cmbmodlookup.Requery
cmbmodlookup = ""
End If

End Sub


Private Sub cmbmodlookup_click()

DoCmd.ShowAllRecords
Me!txtmodule.SetFocus
DoCmd.FindRecord Me!cmbmodlookup
Me!cmbmodlookup.SetFocus

End Sub
--------------------------------------------------------------------------------------------------------------

any help or suggestions would be great

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#2: Apr 25 '07

re: Using a list box to select a record to delete


Run a Delete query. Always remember to back up your database before trying something like this.
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3.    strSQL = "DELETE * FROM TableName WHERE [FieldName]='" & Me!cmbmodlookup & "'"
  4.    DoCmd.RunSQL strSQL
  5.  
Mary
Member
 
Join Date: Mar 2007
Posts: 66
#3: Apr 25 '07

re: Using a list box to select a record to delete


ok cheers once again lol!

i will give it a go and hopefully it will work.
Reply