Message Box - Yes, No actions

Valery

Registered User.
Local time
Today, 09:27
Joined
Jun 22, 2013
Messages
363
Hi all!

I am a newbie... really trying to learn. I have a command button on a subform (main form = frmUnitUpd / subform = frmUnitUpd_Tenants ) to allow the deletion of a record. I wish to:

1) ad a warning message - "Was this record entered by mistake?"

If user clicks on "yes" - have the query called qryDelRecord open to that record (link field is TenantsID) and allow the user to delete the record. When the query is closed, the user should be returned to the form, with that record gone.

If user clicks on "no" - do nothing.

I have this coding from a previous database where someone generous like yourself, helped me. But I don't know how to adapt it.

Code:
Private Sub DeleteCurrentRecord_Click()
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Was this record entered by mistake?"   ' Define message.
    Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.

    ' Display message.
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then    ' User chose Yes.

        MyString = "Yes"    ' Perform some action.
            
  
          Else    ' User chose No.
        MyString = "No" ' Perform some action.
    End If
End Sub

Thank you!
 
have the query called qryDelRecord open to that record ... and allow the user to delete the record.
IMO, the user has already agree to the delete, so just do it. No need to open a query and show them the record again. I would expect to see code like . . .

Code:
   If Response = vbYes Then
[COLOR="Green"]      'replace SomeTable and RowID with your table and field names[/COLOR]
      CurrentDb.Execute "DELETE FROM SomeTable WHERE RowID = " & Me.RowID
      Me.Requery
   End If
 
Opening a query was an extra precaution - as really, no records should be deleted UNLESS they made an extra entry by mistake.

Your coding works great ( :) ) but it deletes the record (quickly!) and does not open the query... Would the fact that these users, including the one who will be "database administrator" are beginners change your mind?

THANK YOU!
 
Last edited:
In that case, why not open the query before you pose the question about whether the record is to be deleted?

Incidentally, for critical deletes where multiple records would be deleted because of cascading, I have a form open which requires the user to type 'Yes' rather than click a button, to avoid an ohno incident.

(Definition: an ohno second is that length of time between accidentally clicking the yes button to "Do you want to delete all? (Y/N)" and the words being uttered 'Oh No!!!')
 
LOLOLOL! Too funny! ohno! Thank you!
 

Users who are viewing this thread

Back
Top Bottom