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 / Forms / March 2008

Tip: Looking for answers? Try searching our database.

Deleting Records

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TeeSee - 09 Mar 2008 17:19 GMT
Access 2003
I have a small table with (among other fields) two check boxes one, if
checked, allows that record to be shown on a form. Once that record
has been used that check box is set to 0 while the other is set to 1
"flagged for deletion".
The line of code --- Set rst = db.OpenRecordset("Select * from
qryItemsForDelete;") I thought became the group of data that the code
following would be affecting. So within the qryItemsForDelete there
are two records flagged for deletion. When I click my command button
to delete the two records I get to delete the first two records in the
underlying table rather than the two that are flagged. Here is the
rest of the code. Any suggestions appreciated.
Please ignore the commented out lines Under construction. Many thanks

Private Sub cmdDelete_Click()
Dim Counter As Integer
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()

Set rst = db.OpenRecordset("Select * from qryItemsForDelete;")
With rst
   Counter = 0
   ' Very important to avoid errors if no records are returned
   If Not (.EOF And .BOF) Then
       'movefirst isn't strictly necessary - but just in case
       '.MoveFirst
       Do Until .EOF
           'do something with record
           Counter = Counter + 1
           DoCmd.RunCommand acCmdSelectRecord
           DoCmd.RunCommand acCmdDeleteRecord
           .MoveNext
       Loop
   End If
   .Close
End With
Set rst = Nothing
Set db = Nothing
'MsgBox ("You are about to DELETE" & " " & Counter & " " & "records"),
vbYesNoCancel
End Sub
Justin - 09 Mar 2008 18:59 GMT
You probably need to do a Me.Refresh or Me.Dirty = False to get the updates
recorded to the table.  Why go through all that to delete records?  You can
run a simple query:

strSQL = "Delete * From MyTable WHERE CheckField = 1;"
DOCmd.RunSQL strSQL

to delete the records.  You can do a DSUM() of the field if you want to tell
the user how many records are being deleted.

> Access 2003
> I have a small table with (among other fields) two check boxes one, if
[quoted text clipped - 38 lines]
> vbYesNoCancel
> End Sub
TeeSee - 09 Mar 2008 19:12 GMT
> You probably need to do a Me.Refresh or Me.Dirty = False to get the updates
> recorded to the table.  Why go through all that to delete records?  You can
[quoted text clipped - 50 lines]
>
> - Show quoted text -
TeeSee - 09 Mar 2008 19:13 GMT
> You probably need to do a Me.Refresh or Me.Dirty = False to get the updates
> recorded to the table.  Why go through all that to delete records?  You can
[quoted text clipped - 50 lines]
>
> - Show quoted text -

Justin .... Thanks for your reply. This is the second question I've
asked in the last two or three days where the answer was to run a
query. Where and how doe you run that query frm a command button?

Thanks
TeeSee - 09 Mar 2008 19:40 GMT
> > You probably need to do a Me.Refresh or Me.Dirty = False to get the updates
> > recorded to the table.  Why go through all that to delete records?  You can
[quoted text clipped - 58 lines]
>
> - Show quoted text -

Sorry Justin ... Forget that last question ... The light just came on.
Thanks again for the response.
 
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.