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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Items From A List Box and Database

Status
Not open for further replies.

Figzus

Programmer
Mar 21, 2005
36
0
0
US
I have this listbox in my Access app that has a rowsourcetype property set to a Table/Query. In this listbox there are a list of different paths an article can belong to. I populate the list box with the following code on form load. It is pulling the strWhere which is an ArticleID set from the previous form.

strWhere = Me.OpenArgs

'Load all the article paths at the beginning if they are available

lstArticlePaths.RowSource = " SELECT ArtPath " & _
" FROM tblTieIn " & _
" WHERE ArtID = " & strWhere

What I am trying to do is if a user wants to delete one of the paths they can do so with a delete button. When they hit delete it will pull up a message box to check if there is something that is highlighted. If a value can be deleted it will delete it from the list box and from the database. Hope this is all the information you need to help me with my little problem.
 
Here is a code sample to delete the item:
Code:
Public Sub DeletePath(PathName as String)
On Error Goto Err_Handler
  Dim sqlTieIn as string
  sqlTieIn = "DELETE * FROM tblTieIn WHERE ArtID=" & PathName &";"
  Setwarnings = False
  DoCmd.RunSQL(sqlTieIn)
Err_Handler:
  Setwarnings = True
End Sub
After all this, requery the rowsource of your listbox.

CMP
This code is untested, I appologize for any errors in spelling or usage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top