Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting from Table 2

Status
Not open for further replies.

AndreB

Programmer
Aug 21, 2001
13
US
What do I have to do to delete a selected value in a ComboBox from a previous saved table?? I don't know how to search for the value on the table and delete it...

thanks
andre
 
Use this code

Dim strSQL as string

strSQL = "Delete * from table1 "
strSQL = strSQL & "where [TableField] = " & me!cbo1

docmd.Runsql strSQL


You may need to modify a bit if you need quotes or '#'s around the table field. Maq B-)
<insert witty signature here>
 
The traditional method of searching for a deleting a record in DAO is as follows:

Sub DeleteTheBugger()
Dim DB as database
Dim rst as recordset

Set DB = CurrentDb
Set rst = DB.OpenRecordset(&quot;Your table name&quot;)
With rst
.Index = &quot;Name of table field that holds the cboValue&quot;
'The field in the table MUST be indexed
.Seek &quot;=&quot;, Me!cboNameOfComboBox
If not .NoMatch then
.Delete
End if
.Close
End with
End Sub

This routine will delete the first record in the table that matches the value in the combo box. A query, on the other hand, will delete ALL records in the table that match the value in the combo box.

Uncle Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top