How to Trigger an Event on the Navigation of Records?

JithuAccess

Member
Local time
Today, 00:11
Joined
Mar 3, 2020
Messages
325
Hello Guys,

This seems to be very simple but I am not getting a solution.

I have a field in my Form "Data Entry By". This field is a mandatory field. So I have wrote this code in the LostFocus Event of "Data Entry By"

Code:
Private Sub strDataEntryBy_LostFocus()

If IsNull(Me.strDataEntryBy) Then
    MsgBox "'Data Entry By' should not be blank", vbInformation, "Blank!!!"
    Cancel = True
End If

End Sub

But I want trigger this code when I navigate the Record. For Example if there are 10 records, when a user navigate from record 1 to record to, I want trigger this code if "Data Entry By" is blank.

I have tried this code in the Before Update event of the Form and it is not working.

Or is there any simple method for this (Except LostFocus please)

Thanks
 
Can you not get the user name at logon and use that?

Environ("Username")
 
use Current event of the form.
 
The best way to do this is to not care at all about that field... UNTIL the user attempts to SAVE the form when it is first created. In the FORM_BEFOREUPDATE event, test the field that you want to not be blank. If it is blank, you can cancel (set CANCEL=1) the update because the _BEFOREUPDATE event has a CANCEL parameter. That way, the form will have a CreatedBy value before you save it and you can't save it until you fill in that blank. If you do that, there will never be a need to do any other testing in any other event.

Note also that jdraw's comment might be appropriate. If you have a possibility of looking up a network ID that is meaningful for your user, or if you have a login on this DB, you have an ID that you can simply store in the form without asking. Again, that "save current user ID" step would occur in the _BEFOREUPDATE event. If you store it earlier on a new form, you might accidentally set yourself up for saving blank forms that ONLY have the user ID, so you have to be careful about WHEN you auto-save anything.

EDITED to correct a sentence that said what I meant backwards.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom