Save User ID field

  • Thread starter hobbit2612 via AccessMonster.com
  • Start date
H

hobbit2612 via AccessMonster.com

Hi, I wonder whether anyone may be able to help me please.

Using the code by Dev Ashish I have a welcome page that shows the user ID of
the person currently logged onto my database. (This is is the first page that
automatically loads upon logon and has no user data entry fields).

Does anyone know please of a way that upon the user being shown this screen
the user ID is saved to my table.

I have tried a couple of things that I thought may work e.g. Me.Dirty method,
Save Record command, but just can't seem to get this to work.

Any help would be greatly appreciated.

Many thanks and regards

Chris
 
H

hobbit2612 via AccessMonster.com

Arvin,

Many thanks for your reply.

I've done what you've suggested and the text box correctly shows the username,
but it doesn't save this to the table.

I've checked that the form is bound to the table, and the text box is bound
to the field in the table with the default value set to =fOSUserName().

Any ideas please?

Thanks and regards

Chris
I assume that you are using this function:

http://www.mvps.org/access/api/api0008.htm

the easiest way to get the username into a table bound to the form is to use
the default value property of a textbox, bound to that field in the table:

=fOSUserName()
Hi, I wonder whether anyone may be able to help me please.
[quoted text clipped - 17 lines]
 
A

Arvin Meyer [MVP]

If the textbox is bound to the table field,and you use =fOSUserName() as the
DefaultValue property, it will save for new records. If you need to change
existing records, you will either need to build a recordset and run an
update, or use code to save it explicitly. Perhaps something like
(untested):

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.txtUsername = =fOSUserName()
End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


hobbit2612 via AccessMonster.com said:
Arvin,

Many thanks for your reply.

I've done what you've suggested and the text box correctly shows the
username,
but it doesn't save this to the table.

I've checked that the form is bound to the table, and the text box is
bound
to the field in the table with the default value set to =fOSUserName().

Any ideas please?

Thanks and regards

Chris
I assume that you are using this function:

http://www.mvps.org/access/api/api0008.htm

the easiest way to get the username into a table bound to the form is to
use
the default value property of a textbox, bound to that field in the table:

=fOSUserName()
Hi, I wonder whether anyone may be able to help me please.
[quoted text clipped - 17 lines]
 
H

hobbit2612 via AccessMonster.com

Arvin,

Thanks for your reply.

There must be something fundamental that I'm doing wrong because I just can't
get the user details to save to the table.

The user data is a new record, so it should save as you say. If I take out
the =fOSUserName() from the default value of the text box and type in the
user name it saves fine to the table. Do you think the problem is because I'm
not typing anything in and hence it doesn't see the automatic user name entry
as the creation of a record?

Many thanks for your time

Regards

Chris
If the textbox is bound to the table field,and you use =fOSUserName() as the
DefaultValue property, it will save for new records. If you need to change
existing records, you will either need to build a recordset and run an
update, or use code to save it explicitly. Perhaps something like
(untested):

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.txtUsername = =fOSUserName()
End Sub
[quoted text clipped - 29 lines]
 
J

John W. Vinson

Arvin,

Thanks for your reply.

There must be something fundamental that I'm doing wrong because I just can't
get the user details to save to the table.

The user data is a new record, so it should save as you say. If I take out
the =fOSUserName() from the default value of the text box and type in the
user name it saves fine to the table. Do you think the problem is because I'm
not typing anything in and hence it doesn't see the automatic user name entry
as the creation of a record?

PMFJI but... a Default Value does not apply until a new record is created (by
dirtying some other field on the form). Access won't create a record for you
automagically; you need to take some action, either manually or in code, to do
so.

What purpose is served by a table with (apparently) only one username field
and nothing else?
 
H

hobbit2612 via AccessMonster.com

John,

Many thanks for your reply.

Yes you are right in all that the table does is store the user name.

Basically what I would like to happen is the user opens the db and is
presented with a welcome page where the user name text box is bound, but
hidden.

From the Welcome page the user will click on a button taking them to another
form 'User details' with further personal information that they can add, view
and amend.

From the knowledge I have, which isn't a great deal as you can see, I think
that I need to record the username first in a separate table so when the user
clicks on the 'User details' form they can only see their details.

Have I got this wrong, is there an easier way?

Thanks and regards

Chris
[quoted text clipped - 8 lines]
not typing anything in and hence it doesn't see the automatic user name entry
as the creation of a record?

PMFJI but... a Default Value does not apply until a new record is created (by
dirtying some other field on the form). Access won't create a record for you
automagically; you need to take some action, either manually or in code, to do
so.

What purpose is served by a table with (apparently) only one username field
and nothing else?
 
J

John W. Vinson

John,

Many thanks for your reply.

Yes you are right in all that the table does is store the user name.

Basically what I would like to happen is the user opens the db and is
presented with a welcome page where the user name text box is bound, but
hidden.

From the Welcome page the user will click on a button taking them to another
form 'User details' with further personal information that they can add, view
and amend.

From the knowledge I have, which isn't a great deal as you can see, I think
that I need to record the username first in a separate table so when the user
clicks on the 'User details' form they can only see their details.

Have I got this wrong, is there an easier way?

There is.

On your opening form use an *unbound* form with an unbound textbox, defaulting
to the user ID. Then in your User Details form, you can make it bound to a
query of the user details table using

=[Forms]![WelcomePageForm]![txtUserID]

as a criterion so the user can only see and edit their own details. On this
form, again you can use the default value - it'll work here because you *are*
dirtying the record by adding othr details.
 
H

hobbit2612 via AccessMonster.com

John,

Many thanks for your reply.

I've followed your advice and I've got it to work!

I really appreciate your help and guidance.

Kind regards

Chris
[quoted text clipped - 15 lines]
Have I got this wrong, is there an easier way?

There is.

On your opening form use an *unbound* form with an unbound textbox, defaulting
to the user ID. Then in your User Details form, you can make it bound to a
query of the user details table using

=[Forms]![WelcomePageForm]![txtUserID]

as a criterion so the user can only see and edit their own details. On this
form, again you can use the default value - it'll work here because you *are*
dirtying the record by adding othr details.
 
Top