Hi Guys
I'm pretty new to all this business so you'll have to excuse my ignorance but this is my situation:
I have created a Form using a wizard to display the contents of a connected Table. I now want to install a Delete facility (Button) to remove the DISPLAYED record. However using the following code deletes the first record in the table, and not the record displayed in the Form:
Private Sub Delete_Click()
If MsgBox("Do You Want To Delete The Record?", 4, "Deletion?"
= 6 Then
Set dbs = CurrentDb
Set MyRS = dbs.OpenRecordset("Customers", dbOpenDynaset)
Forms![Customers].Bookmark = MyRS.Bookmark
With MyRS
.Delete
End With
MsgBox "Record Deleted!!", 64, "No Turning Back!!"
dbs.Close
MyRS.Close
Else
Exit Sub
End If
End Sub
Was my first mistake to use the Wizard? How accurate is my code? I think I'm going wrong because I should have used a SQL query as the first argument after OpenRecordset, instead of just the Table name. Is this correct and if so any clues as to what the SQL should read?
Any help much appreciated.
I'm pretty new to all this business so you'll have to excuse my ignorance but this is my situation:
I have created a Form using a wizard to display the contents of a connected Table. I now want to install a Delete facility (Button) to remove the DISPLAYED record. However using the following code deletes the first record in the table, and not the record displayed in the Form:
Private Sub Delete_Click()
If MsgBox("Do You Want To Delete The Record?", 4, "Deletion?"
Set dbs = CurrentDb
Set MyRS = dbs.OpenRecordset("Customers", dbOpenDynaset)
Forms![Customers].Bookmark = MyRS.Bookmark
With MyRS
.Delete
End With
MsgBox "Record Deleted!!", 64, "No Turning Back!!"
dbs.Close
MyRS.Close
Else
Exit Sub
End If
End Sub
Was my first mistake to use the Wizard? How accurate is my code? I think I'm going wrong because I should have used a SQL query as the first argument after OpenRecordset, instead of just the Table name. Is this correct and if so any clues as to what the SQL should read?
Any help much appreciated.