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!

delete from a list 1

Status
Not open for further replies.

orionsong

Programmer
May 8, 2000
34
MY
Can we delete an item from a list directly?
 
Well yeah.<br>Uh what kind of list?<br>A form <br>A Table<br>A Query<br>A report<br>A listbox on a form.<br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Oops, sorry there. Can we delete from a listbox on a form directly without going into another form?
 
The ListBox itself does not provide any support for deleting data from the tables in it's RecordSource, but you can certainly write code yourself to do this.<br><br>Assuming a listbox called MyList, which displays the primary key (MyKey) from table MyTable and a button on the form named MyDelButton...<br><br><FONT FACE=monospace><br>Sub MyDelButton_Click()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.RunSQL &quot;Delete From MyTable Where MyKey = &quot; & Me!MyList<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;MyList.Requery<br><br>End Sub<br></font><br><br>If MyKey is a text field, change the code above to enclose Me!MyList in single quotes...<br><br>... Where MyKey = <font color=red><b>'</b></font>&quot; & Me!MyList & &quot;<font color=red><b>'</b></font>&quot; <br> <p>Jim Conrad<br><a href=mailto:jconrad3@visteon.com>jconrad3@visteon.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top