Before Delete acting weird (1 Viewer)

CedarTree

Registered User.
Local time
Today, 00:49
Joined
Mar 2, 2018
Messages
404
I have let's say 2 records in a subform. Record 1 has username A and Record 2 has username B. While I'm focused on Record 1, I want to test that the record can only be deleted if username = B (but it's A of course). So I test in "before delete confirm" what username is. And referring to Me.username gives me back username B instead of the record I was on. (After all this, Access asks if I'm sure I want to delete the record). What am I doing wrong? Never had this happen before. Using Access 2016. Thanks!
 

CedarTree

Registered User.
Local time
Today, 00:49
Joined
Mar 2, 2018
Messages
404
Never mind - I'm an idiot. I needed to grab the username in the On Delete event first THEN test in the Before Delete event (the names are confusing... Before sounds to me like it comes before anything else!)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:49
Joined
Feb 19, 2002
Messages
43,293
You might want to review a database I created to use in a couple of videos. The videos concentrate on which events should be used for validation but the database is infinitely useful for learning how to control the event model. Use the existing forms or create your own for testing. As long as you open the event logging form first and put logging code in the events of your test form, they will all show in the window as they happen. I suggest setting the logging code in all form level events. You can copy the event code from frmDefaultEvents_COPY_ME and paste it into your form then add your custom code. To connect the event code to the form, you might have to click into each event to jog Access into connecting the form to the code.

My State form has two useful buttons you might want to add to your test form. One button inserts a separator row in the logging table so you can leave the existing events visible but easily see the break between the old tests and the new one. The second button empties the log table so you can start fresh.

 

Users who are viewing this thread

Top Bottom