Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Login Name in User Field 1

Status
Not open for further replies.

2manyerrors

Programmer
May 14, 2009
36
US
Hi, I hope someone can help me.

I've implemented successfully the login form from:

but now I would like to attach that username into forms that is the user uses to input data into.

For example, the user logs into the db then when they open a form to input data into, there login name will automatically be placed into a text field called username. This is to track which user made what inputs.

I hope someone can help. Thank you a head of time.
 
I forgot to mention that I am using access 2003. I need this to work for access 2003 and 2007. Thank you.
 
How are ya 2manyerrors . . .
[ol][li]You need to add a textfield to each table that can be edited thru forms by the user. Name the field [blue]usrName[/blue].[/li]
[li]For each of the forms above add the bound field [blue]usrName[/blue].[/li]
[li]When a qualified name & password are entered thru your login form, your going to hold the name in a [blue]public variable[/blue]. So in the [blue]declaration section[/blue] of a module in the modules window, copy/paste the following:
Code:
[blue]Public LogName As String[/blue]
[/li]
[li]In your Login form you update the public variable with:
Code:
[blue]   LogName = Me.cboEmployee[/blue]
[/li]
[li]We'll need a function to pass [blue]LogName[/blue] back to the forms. So in the same module, copy/paste the following function:
Code:
[blue]Public Function curLogName() As String
   curLogName = LoginName
End Function[/blue]
[/li]
[li]Finally ... in the [blue]On Load[/blue] event of the approriate forms, copy/paste the following:
Code:
[blue]   Me.usrName = curLogName()[/blue]
[/li]
[li][blue]Done![/blue] ... perform your testing.[/li][/ol]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Woops [blush]

There's an error in the function I gave:
Code:
[blue][tt]          curLogName = LoginName
should be curLogName = [purple][b]LogName[/b][/purple][/tt][/blue]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
2manyerrors . . .

In 4. of my post [blue]6 Nov 10 13:54[/blue], if [blue]cboEmployee[/blue] is not the name of your combobox change it accordingly.

Set a break point in your login code so you can check that the login name is saved in the public variable and post back the code in the button.

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Good morning and thank you for your help. I did what you said and I got it to work partially. The form usrName field is pulling only the auto-id of my tblEmployees. In my tblEmployees where the usernames and passwords are stored, I have the following:
IngEmpID
strEmpName
strEmpPassword
strAccess

I would like the strEmpName to be the field that gets displayed. Right now the IngEmpID is being displayed in the entry form.

Thanks again.
 
2manyerrors . . .

For the code in the button add the line in [purple]purple[/purple] where you see it:
Code:
[blue]   If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
   
      lngMyEmpID = Me.cboEmployee.Value
      [purple][b]LogName = Me.cboEmployee.Column(1[/b])[/purple][/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank you TheAceMan1. It worked. But there is one problem. When I test it, the first form works but then when I tab over to fill out another/second/third form(not closing the forms) the user name is no longer in the box. Any idea to fix this.

Hi jontout. You have the right idea but unfortunately I must have the login form. Thanks for your input.
 
2manyerrors . . .

Remove ...
Code:
[blue]   Me.usrName = curLogName()[/blue]
... from the forms [blue]On Load[/blue] event and in the [blue]Default Value[/blue] property of [blue]usrName[/blue] enter:
Code:
[blue]=curLogName()[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
YEAH!!!

TheAceMan1, thank you soooo much!!! It all worked perfect!!

My only regret is that I wish I can help you too.
Thank you soooooo much for all your time and help. I wish you all the best!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top