I have attached a sample of form which is not executable because I have just started coding the form. All fields are bound fields. The attachment do not have other objects too.
Upon successfully loading the form , the Operator text box should be filled up with the login ID from frmLogin (I do not attach this form inside the attachment).
Form work well with the first record. However, when I start creating second and more records, I have not idea how to auto reset the login ID to the Operator text box. Can Anyone suggest some help to me to resolve the problem ?
From your brief description and the fact that it works for the first record only, it would appear that you're assigning the UserID to the Operator Textbox using Form_Load or Form_Open event. To have this occur for all new records added during this session, you'd need to use the Form_Current event, instead, something along the lines of:
Code:
Private Sub Form_Current()
If Me.NewRecord Then
Me.OperatorTextboxName = UserID
End If
End Sub
From your brief description and the fact that it works for the first record only, it would appear that you're assigning the UserID to the Operator Textbox using Form_Load or Form_Open event. To have this occur for all new records added during this session, you'd need to use the Form_Current event, instead, something along the lines of:
Code:
Private Sub Form_Current()
If Me.NewRecord Then
Me.OperatorTextboxName = UserID
End If
End Sub
Thanks for the above code. However, I am wondering the code below is executed when I try to DELETE a record. How to prevent this because I have other codes go along after the OperatorTextboxName = UserID ?
If Me.NewRecord Then
Me.OperatorTextboxName = UserID
End If
Where have you placed the code? There's no reason for this code to run when Deleting a Record, unless you've placed it in an event related to deletion. It was supposed to be in the Form_Current event.
Where have you placed the code? There's no reason for this code to run when Deleting a Record, unless you've placed it in an event related to deletion. It was supposed to be in the Form_Current event.
However, if there are total of 3 records have been typed in, with the Form_Current event written, I can't delete the last record only. This means the earlier 2 records can be successfully deleted.
See below attachment. However, record can't be smoothly deleted after I comment the Form_Current event
I have substituted with the Form_BeforeInsert event n it works .
Private Sub Form_Current() If Me.NewRecord Then Me.OperatorTextboxName = UserID End If End Sub
If there are some condition fail, how to undo the NewRecord method ?