Load event question

  • Thread starter Thread starter Iago
  • Start date Start date
I

Iago

I found this code along with it's function on this discussion group. It works
great but I want it to populate the text field when the form loads.
How can I get the following code on the Form_Load()?
fOSUserName() is a defined function.

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

' Set bound controls to system date and time and current user name
Me.DateModified = Now()
Me.ModifiedBy = fOSUserName()

BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub
 
You should be able to just copy the same code into the On Load event.

Private Sub Form_Load()

Me.DateModified = Now()
Me.ModifiedBy = fOSUserName()

End Sub
 
The 'modifiedby' field is what I found on the forum, my field is actually
called 'User' and I am using it to capture what user is entering data into
the form. I want it to populate automatically when the user opens the form.
 
The 'modifiedby' field is what I found on the forum, my field is
actually called 'User' and I am using it to capture what user is
entering data into the form. I want it to populate automatically
when the user opens the form.
I think you really would want it to save the user when the user
actually updates the information in the form to the table. To do that
use the Form's Before_Update Event.

Using the Load event means that EVERY user will be shown as the USER
in EVERY ROW that is looked at, as well as the ones that do get new
data entered..

I'm sure that's not what you really want.

as to the different field name, just change me.ModifiedBy to me.User

Bob Q
 
Bob Quintal wrote:
"Using the Load event means that EVERY user will be shown as the
USER in EVERY ROW that is looked at, as well as the ones that do
get new data entered."

Actually, placing this in the Form_Load event will only effect the
first record displayed, not every record!
If the load event places the data into an unbound box, and code in
another event writes it to the table, it will affect every row.
 
Back
Top