Load event question

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
 
G

ghetto_banjo

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
 
L

Linq Adams via AccessMonster.com

What is your point in placing it in the Load event? This will only cause the
fields in the first record that loads to be changed, and what if that record
isn't actually modified? It will now have erroneous information.
 
I

Iago

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.
 
B

Bob Quintal

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
 
L

Linq Adams via AccessMonster.com

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!
 
B

Bob Quintal

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top