Delete Records and Table....

bmwilson

Registered User.
Local time
Today, 12:49
Joined
Dec 6, 2001
Messages
18
Private Sub DeleteComponent_Click()
Dim strTableName As String

strTableName = NewComponentName.Value 'Value from a combobox
DoCmd.DeleteObject acTable, strTableName

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
NewComponentName.Requery
NewComponentName.SetFocus

End Sub

When I use this code to delete a table (referred to by the combobox) and a record with the same name in a table called ComponentTypes, it deletes the wrong record in the table. What am I doing wrong? It deletes the table ok but not the correct record.
 
The code you are using to delete a record will select the record that is being displayed on the active form and then delete it. I don't think that is your intention. You'll need to actually find the record that matches some criteria. Use a delete query with parameters. It will be simpler.
 

Users who are viewing this thread

Back
Top Bottom