Requery altering incorrect records

W

Wullie

I have created a database and want to give users the option to
add/edit/remove staff members.

The add and edit I can get to work how I would like and I thought that the
delete was working too, but it appears to be deleting the existing record,
but moving the records details to another record (eg, I delete person X with
an ID of 7, the person with ID 1 has the name of 7).

Can anyone look at my code and advise where I am going wrong and help advise
how to fix it?

-------------------------

Private Sub back_to_accts_Click()
On Error GoTo Err_Back_to_accts_Click

Dim stDocOpenName As String
Dim stDocCloseName As String

stDocOpenName = "StaffMenu"
stDocCloseName = "RemoveStaffMember"
DoCmd.Close acForm, stDocCloseName, acSaveNo
DoCmd.OpenForm stDocOpenName

Exit_Back_to_accts_Click:
Exit Sub

Err_Back_to_accts_Click:
MsgBox Err.Description
Resume Exit_Back_to_accts_Click

End Sub


Private Sub Delete_Item_Click()
On Error GoTo Err_Delete_Item_Click

Dim nameToRemove As Integer
Dim rs As DAO.Recordset

Set rs = currentDB.OpenRecordset("Staff")

nameToRemove = Me.Remove_Current_List.Value

YesNo = MsgBox("Are you sure you wish to remove the selected record " &
vbCrLf & _
"'" & nameToRemove & "'", vbExclamation + vbYesNo, "Confirm
Delete")
If YesNo = vbYes Then
rs.Index = "ID" 'set the index
rs.Seek "=", nameToRemove 'Seek the record
rs.Delete
End If
rs.Close
DoCmd.Requery "Remove Current List"

Exit_Delete_Item_Click:
Exit Sub

Err_Delete_Item_Click:
MsgBox Err.Description
Resume Exit_Delete_Item_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top