Auto Populate Username

B

benjaminkmartin

I am creating a database with user-level security. One of the forms
has a field labeled "username." I would like this field to auto-
populate with the username of the user that is logged in. Is there a
way to do that?
 
B

Bob Larson

Version 2000-2003
1. Go to the Database Window and to the Modules area

2. Click on NEW Module

3. Paste the code in after the Option Compare Database

4. Save the module with a name like modAPI

5. To put the user name in the text box - in the form's On Load event you
can use
Me.YourTextBoxNameHere = fOSUsername

Version 2007
1. Go to the CREATE tab on the ribbon

2. On the OTHER group at the end of the CREATE tab, click the MACRO dropdown
and select MODULE.

3. Paste the code in after the Option Compare Database

4. Save the module with a name like modAPI

5. To put the user name in the text box - in the form's On Load event you
can use
Me.YourTextBoxNameHere = fOSUsername


--

Thanks,

Bob Larson
Access MVP
Administrator, Access World Forums
Utter Access VIP

Free Access Tutorials and Resources: http://www.btabdevelopment.com



I'm sorry, I'm new to Access. How do I implement the code?
 
B

benjaminkmartin

I put all the information in like you suggested, except for one small
thing. There is no "On Load" event option for me to use, so I just
used "On Enter." I hope that's not my problem...

After I put the code in the text box, I attempt to enter information
into the form and I get the error message, "Microsoft Access can't
find the macro, 'Me.' The macro (or it's macro group) doesn't exist or
the macro is new and hasn't been saved. Note that when you enter the
macrogroupname. macroname syntax in an argument, you must specify the
name the macro's macro group was last saved under."

And if it helps at all I have Microsoft Access 2003.

Thanks
 
B

benjaminkmartin

I put all the information in like you suggested, except for one small
thing.  There is no "On Load" event option for me to use, so I just
used "On Enter."  I hope that's not my problem...

After I put the code in the text box, I attempt to enter information
into the form and I get the error message, "Microsoft Access can't
find the macro, 'Me.' The macro (or it's macro group) doesn't exist or
the macro is new and hasn't been saved.  Note that when you enter the
macrogroupname. macroname syntax in an argument, you must specify the
name the macro's macro group was last saved under."

And if it helps at all I have Microsoft Access 2003.

Thanks

















- Show quoted text -

never mind, I figured it out
 

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