Hi
I hope someone can help me.
Since upgrading to Office 2016, I now receive the 3061 run time error when I attempt to delete a record in my database. I am a novice access user and whilst able to create queries and reports, my knowledge of vba is limited so please bear with me.
The following code is designed to delete a single record and move a subset of the data to a 'deleted people' table:
After searching, the solution might be with adding a ' character in the where statement but I'm not sure if this is correct. The database is used to manage volunteers who donate time to a charity.
Many thanks
Chris
I hope someone can help me.
Since upgrading to Office 2016, I now receive the 3061 run time error when I attempt to delete a record in my database. I am a novice access user and whilst able to create queries and reports, my knowledge of vba is limited so please bear with me.
The following code is designed to delete a single record and move a subset of the data to a 'deleted people' table:
Code:
Private Sub cboDelReason_AfterUpdate()
Dim rstPubs As DAO.Recordset
On Error GoTo Err_cboDelReason_AfterUpdate
DoCmd.Hourglass True
DoCmd.SetWarnings False
zStr = "SELECT tblPeople.PeopleID, tblPeople.Title, tblPeople.[First Name], "
zStr = zStr & "tblPeople.[Last Name], tblPeople.Postcode, tblPeople.Telephone, tblPeople.[Date of Entry], "
zStr = zStr & "tblRoles.[Role Name], tblPeopleRoles.Barcode "
zStr = zStr & "FROM tblPeople LEFT JOIN (tblPeopleRoles LEFT JOIN tblRoles ON "
zStr = zStr & "tblPeopleRoles.RoleID = tblRoles.RoleID) ON "
zStr = zStr & "tblPeople.PeopleID = tblPeopleRoles.PeopleID "
zStr = zStr & "WHERE ((tblPeople.PeopleID) "
zStr = zStr & "Like '" & [Forms]![frmEditPeople]![PeopleID] & "')"
Set dbs = CurrentDb()
Set rstData = dbs.OpenRecordset(zStr, dbOpenDynaset)
rstData.MoveFirst
If rstData.BOF Then
Else
Set rst = dbs.OpenRecordset("tblDelPeople", dbOpenDynaset)
rst.AddNew
rst!Title = Me!Title
rst![First Name] = Me![First Name]
rst![Last Name] = Me![Last Name]
rst!PeopleID = Me![PeopleID]
rst!Postcode = Me!Postcode
rst![Date Joined] = Me![Date of Entry]
rst![Date Deleted] = Format(Now(), "dd/mm/yyyy")
rst![Telephone] = Me![Telephone]
rst!Reason = Me!cboDelReason
rst.Update
Set rstPubs = dbs.OpenRecordset("tblDelPeople_Roles", dbOpenDynaset)
Do Until rstData.EOF
rstPubs.AddNew
rstPubs!PeopleID = rstData![PeopleID]
rstPubs![Pub] = rstData![Role Name]
rstPubs![Barcode] = rstData![Barcode]
rstPubs.Update
rstData.MoveNext
Loop
zStr = "DELETE tblPeople.*, tblPeople.PeopleID "
zStr = zStr & "FROM tblPeople "
zStr = zStr & "WHERE ((tblPeople.PeopleID)= " & Me![PeopleID] & ")"
dbs.Execute zStr
Me.Requery
Me.Refresh
Me.PeopleID.SetFocus
Me.cboDelReason.Visible = False
End If
Exit_cboDelReason_AfterUpdate:
rst.Close
rstData.Close
DoCmd.Hourglass False
DoCmd.SetWarnings True
Set dbs = Nothing
Exit Sub
Err_cboDelReason_AfterUpdate:
Select Case Err
Case 91
Resume Next
Case 3021
Resume Exit_cboDelReason_AfterUpdate
Case Else
MsgBox Err.Number & ":- " & Err.Description
Resume Next
End Select
End Sub
Many thanks
Chris
Last edited by a moderator: