Updating a yes/no field in an existing record (1 Viewer)

Rx_

Nothing In Moderation
Local time
Yesterday, 21:54
Joined
Oct 22, 2009
Messages
2,803
Example code - no question - comments welcome
On a table, added a yes/no field named [Deleted]
With the current record in a form, the user can click a command button that ask them if they want to mark this record as deleted.
The the Delete field is changed. The user can use a list box to mark others (the list box shows the status).
Instead of actually deleting records, marking a record as deleted provides another level of reporting.
the if me.dirty line ensures that there are no edits and makes sure that one date field is completed. It is not a required field, but a "good to know" field.

Code:
Private Sub cmdDeleteRecord_Click()
On Error GoTo Proc_error
Dim rsMarkDeleted           As dao.Recordset
Dim Answer                  As String
If Me.Dirty = False And Not IsNull(Me.txtDateSubmitted) Then
    Answer = MsgBox("This will Mark the Record for Deletion, are you absolutely sure?", vbCritical + vbYesNo, "WARNING - No Undo")
            If Answer = vbNo Then
                MsgBox "Nothing changed", vbOKOnly, "Canceled Operation"
             Else
                            Set rsMarkDeleted = Me.Recordset
                            rsMarkDeleted.Edit
                            rsMarkDeleted.Fields("Deleted").Value = True
                            rsMarkDeleted.Update
 
                            MsgBox "File was marked as Deleted, Please close and re-open Notification  form to see change", vbOKOnly, "Record Marked as Deleted - Chooe another or Close / Reopen to See changes"
              End If
Else
        MsgBox "Date Submitted is not completed or the record is still locked for editing", vbOKOnly, "Cancel Mark for Editing"
 
End If
Proc_exit:
    On Error Resume Next
    Exit Sub
Proc_error:
    Select Case Err.Number
    ' Case ###
    Case Else
    '    
    End Select
End Sub
 

HiTechCoach

Well-known member
Local time
Yesterday, 22:54
Joined
Mar 6, 2006
Messages
4,357
Example code - no question - comments welcome
On a table, added a yes/no field named [Deleted]
With the current record in a form, the user can click a command button that ask them if they want to mark this record as deleted.
The the Delete field is changed. The user can use a list box to mark others (the list box shows the status).
Instead of actually deleting records, marking a record as deleted provides another level of reporting.
the if me.dirty line ensures that there are no edits and makes sure that one date field is completed. It is not a required field, but a "good to know" field.

Code:
Private Sub cmdDeleteRecord_Click()
On Error GoTo Proc_error
Dim rsMarkDeleted           As dao.Recordset
Dim Answer                  As String
If Me.Dirty = False And Not IsNull(Me.txtDateSubmitted) Then
    Answer = MsgBox("This will Mark the Record for Deletion, are you absolutely sure?", vbCritical + vbYesNo, "WARNING - No Undo")
            If Answer = vbNo Then
                MsgBox "Nothing changed", vbOKOnly, "Canceled Operation"
             Else
                            Set rsMarkDeleted = Me.Recordset
                            rsMarkDeleted.Edit
                            rsMarkDeleted.Fields("Deleted").Value = True
                            rsMarkDeleted.Update
 
                            MsgBox "File was marked as Deleted, Please close and re-open Notification  form to see change", vbOKOnly, "Record Marked as Deleted - Chooe another or Close / Reopen to See changes"
              End If
Else
        MsgBox "Date Submitted is not completed or the record is still locked for editing", vbOKOnly, "Cancel Mark for Editing"
 
End If
Proc_exit:
    On Error Resume Next
    Exit Sub
Proc_error:
    Select Case Err.Number
    ' Case ###
    Case Else
    '    
    End Select
End Sub


Curious, why do you use a a second recordset to set the deleted flag? Why the extra overhead?

Why not change:

Code:
                            Set rsMarkDeleted = Me.Recordset
                            rsMarkDeleted.Edit
                            rsMarkDeleted.Fields("Deleted").Value = True
                            rsMarkDeleted.Update

to just:
Code:
                            Me.Deleted = True
                            Me.Dirty = False

Will the form always only have a single record in the recordset? If not, how do you insure that you are updating the correct record in the rsMarkDeleted recordset?
 

boblarson

Smeghead
Local time
Yesterday, 20:54
Joined
Jan 12, 2001
Messages
32,059
Also, why not a simple update query instead?
 

Rx_

Nothing In Moderation
Local time
Yesterday, 21:54
Joined
Oct 22, 2009
Messages
2,803
After posting, I had in fact gone back to use:
Set rsMarkDeleted = Me.Recordset
Very good point. Your right, it is a unnecessary overhead. Hope others can learn from my haste.

Also, good point about this being a single table. The database being updated had grown organically over time, the data had been normalized back to a single table.

There are about 30 users on a front end, linked to a back end (_be) table.
Just wondering if the .edit with an .update adds to prevent possible data collisions?
Because the two line suggestion is very appealing.

The update - In this case in-house developers kind of use wizards for design. I have yet to see them use an update query anywhere. I personally agree that Updates are a very valid consideration as well.

Really appreciate the comments.
 

Users who are viewing this thread

Top Bottom