Windows user name

  • Thread starter Thread starter justinc
  • Start date Start date
J

justinc

I was wondering if there is a way to automatically get the windows user name
to pop in a field. i have a field called reps and i need it to pull in the
currently logged on windows user name into that field. im using Access 2003.
Any help would be great
 
i did that now its giving me an error. plus i forgot to mention i have
multiple people using this app so can i still use it to pull in and save
everyone's user name? i need the user names for a report that my boss wants
run.
thanks for the help im very new to this

Chris O'C via AccessMonster.com said:
No prob. Here are the steps:

1 - Create a new standard code module and paste the code on this page
http://www.mvps.org/access/api/api0008.htm into it. (Menu: Insert > Module)
Name the module basApiFunctions. (Whatever you do, don't name the module the
same as any of the procedures in your app.) Compile the code.

2 - Create a new query based on the table. (Menu: Insert > Query)

3 - Create a new form based on the query. (Menu: Insert > Form) You base
the form on the query instead of the underlying table so you have flexibility
to add other tables, sort and filter the data in the query.

4 - Access will name the text box bound to the reps field the same name.
While the form is in design view, change that text box's name to txtReps in
the form's properties.

5 - Go to the events tab in the form's properties. Scroll down till you see
OnOpen. Click on the combo box next to it and choose [Event Procedure].
Click on the three dots to the right of the combo box to open the code module
in the open event. Add the code I suggested in my earlier post and error
handling. Your Form_Open procedure should look a lot like this:

'start of code:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Proc_Err

Me.txtReps = fOSUserName()

Proc_Exit:

Exit Sub

Proc_Err:
MsgBox Err.Number & vbcrlf & Err.Description
Err.Clear
Resume Proc_Exit

End Sub

'end of code

Compile the code and save the form. When the form opens, your windows user
name will show in the text box and be saved in the table.

Chris
Microsoft MVP

thanks for the help, but im kinda new to this so can you explain how to do
this. thanks
 
the error is:
-2147352567
You can't assign a value to this object

im using the the from to track customer calls by the Rep Name, so when a new
record is created the user doesnt have to type there name in every time it
just pulls in there currently logged on name in to the database so when we
run the report it will show the user name with all of info that the user did
for that call.
thanks again for all your help! it is very much appreciated!!
 
Back
Top