Currentuser

J

jim

I would like to return the Current user to a field in a
record. However, when i try this, the current user is
added to that field in every record, not just the current
one. Can anybody help?
 
S

Sandra Daigle

Hi Jim,

It sounds like you are using a calculated control to display the current
user on a continuous form. If this is the case then it is also likely that
nothing is getting saved in the table - it's only a display value.

Instead of putting an expression in the ControlSource of the control you
need to bind the Control to a field in the table by putting (or selecting) a
fieldname in the ControlSource. Then in the BeforeUpdate event of the form,
assign the value to the control with a statement like this:

me.txtUserName=currentuser()
 
G

Guest

Hi Sandra, thanks for the response. What I actually did
was this:
I created a field in the table, called REGISTERED_BY.
To one of the fields, SEARCH_ADDRESS, in the form (Not a
contiuous form, by the way) I attached the following code;

Private Sub SEARCH_ADDRESS_Enter()
REGISTERED_BY = CurrentUser
End Sub

When I enter the SEARCH_ADDRESS field on the form, "Admin"
is entered into the REGISTERED_BY text box, which is just
what I want. However, when I scroll through the rest of
the records, "Admin" has been entered in them as well -
which isn't what I want. I've changed the code to

Me. REGISTERED_BY = CurrentUser

But the same thing happens. Hope this makes it clearer.

Any more ideas? I'd really appreciate some help.

Jim.
-----Original Message-----
Hi Jim,

It sounds like you are using a calculated control to display the current
user on a continuous form. If this is the case then it is also likely that
nothing is getting saved in the table - it's only a display value.

Instead of putting an expression in the ControlSource of the control you
need to bind the Control to a field in the table by putting (or selecting) a
fieldname in the ControlSource. Then in the BeforeUpdate event of the form,
assign the value to the control with a statement like this:

me.txtUserName=currentuser()


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

I would like to return the Current user to a field in a
record. However, when i try this, the current user is
added to that field in every record, not just the current
one. Can anybody help?


.
 
A

Alex Ivanov

Jim,

I would recommend to set a default value of the search_address field to
CurrentUser()
and remove your event handler.
You may also consider moving your code to a different event such as
BeforeUpdate
or check if the field is null before assigning it a new value.

The Enter event fires every time the text box receives focus overwriting
previous value.
This event fires also when you scroll the records while control has the
focus.
--
Please reply to NG only. The email address is not monitored.

Alex.

Hi Sandra, thanks for the response. What I actually did
was this:
I created a field in the table, called REGISTERED_BY.
To one of the fields, SEARCH_ADDRESS, in the form (Not a
contiuous form, by the way) I attached the following code;

Private Sub SEARCH_ADDRESS_Enter()
REGISTERED_BY = CurrentUser
End Sub

When I enter the SEARCH_ADDRESS field on the form, "Admin"
is entered into the REGISTERED_BY text box, which is just
what I want. However, when I scroll through the rest of
the records, "Admin" has been entered in them as well -
which isn't what I want. I've changed the code to

Me. REGISTERED_BY = CurrentUser

But the same thing happens. Hope this makes it clearer.

Any more ideas? I'd really appreciate some help.

Jim.
-----Original Message-----
Hi Jim,

It sounds like you are using a calculated control to display the current
user on a continuous form. If this is the case then it is also likely that
nothing is getting saved in the table - it's only a display value.

Instead of putting an expression in the ControlSource of the control you
need to bind the Control to a field in the table by putting (or selecting) a
fieldname in the ControlSource. Then in the BeforeUpdate event of the form,
assign the value to the control with a statement like this:

me.txtUserName=currentuser()


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

I would like to return the Current user to a field in a
record. However, when i try this, the current user is
added to that field in every record, not just the current
one. Can anybody help?


.
 
S

Sandra Daigle

Agreed - this code does not belong in the Enter event of the Search_address
control. It belongs in the BeforeUpdate event.

As Alex has mentioned you could use the Default property but this will only
take care of entering the username of the user who creates the record. It
will not record the user that updates an existing record. For this you must
use the BeforeUpdate event.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Alex said:
Jim,

I would recommend to set a default value of the search_address field
to CurrentUser()
and remove your event handler.
You may also consider moving your code to a different event such as
BeforeUpdate
or check if the field is null before assigning it a new value.

The Enter event fires every time the text box receives focus
overwriting previous value.
This event fires also when you scroll the records while control has
the focus.

Hi Sandra, thanks for the response. What I actually did
was this:
I created a field in the table, called REGISTERED_BY.
To one of the fields, SEARCH_ADDRESS, in the form (Not a
contiuous form, by the way) I attached the following code;

Private Sub SEARCH_ADDRESS_Enter()
REGISTERED_BY = CurrentUser
End Sub

When I enter the SEARCH_ADDRESS field on the form, "Admin"
is entered into the REGISTERED_BY text box, which is just
what I want. However, when I scroll through the rest of
the records, "Admin" has been entered in them as well -
which isn't what I want. I've changed the code to

Me. REGISTERED_BY = CurrentUser

But the same thing happens. Hope this makes it clearer.

Any more ideas? I'd really appreciate some help.

Jim.
-----Original Message-----
Hi Jim,

It sounds like you are using a calculated control to display the current
user on a continuous form. If this is the case then it is also likely that
nothing is getting saved in the table - it's only a display value.

Instead of putting an expression in the ControlSource of the control you
need to bind the Control to a field in the table by putting (or selecting) a
fieldname in the ControlSource. Then in the BeforeUpdate event of the form,
assign the value to the control with a statement like this:

me.txtUserName=currentuser()


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


jim wrote:
I would like to return the Current user to a field in a
record. However, when i try this, the current user is
added to that field in every record, not just the current
one. Can anybody help?


.
 
J

Jim

Alex, many thanks. You were right about the event running
as I scrolled through the records. I have attached the
code to the Before Update and it works fine. Thanks
again, Jim
-----Original Message-----
Jim,

I would recommend to set a default value of the search_address field to
CurrentUser()
and remove your event handler.
You may also consider moving your code to a different event such as
BeforeUpdate
or check if the field is null before assigning it a new value.

The Enter event fires every time the text box receives focus overwriting
previous value.
This event fires also when you scroll the records while control has the
focus.
--
Please reply to NG only. The email address is not monitored.

Alex.

Hi Sandra, thanks for the response. What I actually did
was this:
I created a field in the table, called REGISTERED_BY.
To one of the fields, SEARCH_ADDRESS, in the form (Not a
contiuous form, by the way) I attached the following code;

Private Sub SEARCH_ADDRESS_Enter()
REGISTERED_BY = CurrentUser
End Sub

When I enter the SEARCH_ADDRESS field on the form, "Admin"
is entered into the REGISTERED_BY text box, which is just
what I want. However, when I scroll through the rest of
the records, "Admin" has been entered in them as well -
which isn't what I want. I've changed the code to

Me. REGISTERED_BY = CurrentUser

But the same thing happens. Hope this makes it clearer.

Any more ideas? I'd really appreciate some help.

Jim.
-----Original Message-----
Hi Jim,

It sounds like you are using a calculated control to display the current
user on a continuous form. If this is the case then it
is
also likely that
nothing is getting saved in the table - it's only a display value.

Instead of putting an expression in the ControlSource
of
the control you
need to bind the Control to a field in the table by putting (or selecting) a
fieldname in the ControlSource. Then in the
BeforeUpdate
event of the form,
assign the value to the control with a statement like this:

me.txtUserName=currentuser()


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


jim wrote:
I would like to return the Current user to a field in a
record. However, when i try this, the current user is
added to that field in every record, not just the current
one. Can anybody help?


.


.
 
J

Jim

Sandra. See my reply to Alex. Thanks for your help,
also. Between you both you've sorted my problem. This is
the first time I've been online and used a forum to solve
a problem, so I'm very impressed!
Jim
-----Original Message-----
Agreed - this code does not belong in the Enter event of the Search_address
control. It belongs in the BeforeUpdate event.

As Alex has mentioned you could use the Default property but this will only
take care of entering the username of the user who creates the record. It
will not record the user that updates an existing record. For this you must
use the BeforeUpdate event.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Alex said:
Jim,

I would recommend to set a default value of the search_address field
to CurrentUser()
and remove your event handler.
You may also consider moving your code to a different event such as
BeforeUpdate
or check if the field is null before assigning it a new value.

The Enter event fires every time the text box receives focus
overwriting previous value.
This event fires also when you scroll the records while control has
the focus.

Hi Sandra, thanks for the response. What I actually did
was this:
I created a field in the table, called REGISTERED_BY.
To one of the fields, SEARCH_ADDRESS, in the form (Not a
contiuous form, by the way) I attached the following code;

Private Sub SEARCH_ADDRESS_Enter()
REGISTERED_BY = CurrentUser
End Sub

When I enter the SEARCH_ADDRESS field on the form, "Admin"
is entered into the REGISTERED_BY text box, which is just
what I want. However, when I scroll through the rest of
the records, "Admin" has been entered in them as well -
which isn't what I want. I've changed the code to

Me. REGISTERED_BY = CurrentUser

But the same thing happens. Hope this makes it clearer.

Any more ideas? I'd really appreciate some help.

Jim.

-----Original Message-----
Hi Jim,

It sounds like you are using a calculated control to
display the current
user on a continuous form. If this is the case then it is
also likely that
nothing is getting saved in the table - it's only a
display value.

Instead of putting an expression in the ControlSource of
the control you
need to bind the Control to a field in the table by
putting (or selecting) a
fieldname in the ControlSource. Then in the BeforeUpdate
event of the form,
assign the value to the control with a statement like
this:

me.txtUserName=currentuser()


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


jim wrote:
I would like to return the Current user to a field in a
record. However, when i try this, the current user is
added to that field in every record, not just the
current
one. Can anybody help?


.


.
 

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