Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / January 2006

Tip: Looking for answers? Try searching our database.

creating a delete button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jim Bob - 12 Jan 2006 01:11 GMT
Hi,
I have a form with a list box that shows the contents of a table and
managed to create an add record button with the wizard.
(DoCmd.GoToRecord , , acNewRec)

Now i want to make a delete record button based on what was selected
from the list box.

I have the basic code:
   DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
   DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

but how do i pass the value of what i want to delete to the delete
button? (ie me.mylist.value)
Thanks
Wayne Morgan - 12 Jan 2006 16:17 GMT
Since you are making selections from a listbox, I assume you want to be able
to delete multiple records if multiple items were selected in the listbox.
This can be done using a Delete query with the values from the listbox
concatenated in. The trick is to make sure that the values you are getting
from the listbox are the ones you want. If they aren't unique IDs for the
records to be deleted, be aware that any record that matches the selection
will be deleted.

Example:
Dim strSelection As String, varItem As Variant
Dim strSQL As String
For Each varItem in Me.lstMyListbox.ItemsSelected
   'This assumes numbers as the values from the listbox
   strSelection = strSelection & Me.lstMyListbox.ItemDate(varItem) & ","
   'If the values are strings, use the following
   'strSelection = strSelection & """" & Me.lstMyListbox.ItemDate(varItem)
& ""","
Next
'Remove the last ","
strSelection = Left(strSelection, Len(strSelection) -1)
strSQL = "DELETE * FROM MyTable WHERE MyTable.FieldName IN (" & strSelection
& ");"
CurrentDb.Execute strSQL, dbFailOnError

Of course, if you have spaces in the table or field names, place brackets
[ ] around them.

Signature

Wayne Morgan
MS Access MVP

> Hi,
> I have a form with a list box that shows the contents of a table and
[quoted text clipped - 13 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
jim Bob - 13 Jan 2006 03:04 GMT
Thanks Wayne,
problem solved.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.