Logon Form - Log Current User (1 Viewer)

mikebaldam

Registered User.
Local time
Today, 21:50
Joined
Oct 29, 2002
Messages
114
Here's the problem (And believe me its driving me MAD)....probably really simple but I cant seem to suss it.


I have my own Logon form with a Combo Box txtUserName to pull up the username from an Employees table. This works fine.

I want to pull the username from the form above into a field in another table.... so that when the user activates a button (in a form) thier userid is inserted into an already existing record's field.
(in this case the table EMP and field QC)

I've tried to use an update query but I cant get it to pull the username form the form (I've left the form open)

I've also been trying to do this though global variables but haven't had much luck.... (my VB is non-existant)

I'm guessing that this can be done through a amend query with a lookup to the form called frmlogon, but I can't get it to pull the data and add into an existing record.

It may be of help to show what I have so far........

below are:

logon VB

Variables VB
-----------------------------LOGON-VB------------------------------------
Private Sub Form_Click()
Option Compare Database
Private intLogonAttempts As Integer

Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.txtUserName) Or Me.txtUserName = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.txtUserName.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtpassword) Or Me.txtpassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtpassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this matches value chosen in combo box

If Me.txtpassword.Value = DLookup("Password", "Employees", "[ID]=" & Me.txtUserName.Value) Then
ID = Me.txtUserName.Value
GetUserName = Me![txtUserName]




'Close logon form and open Main Menu Form

' code to close form removed ****** DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Main Menu"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtpassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub
----------VARIABLES-VB--------------------------------------------------------


Option Compare Database
Dim PstrUserName As String

Function SetUser(UserName As String) As String
PstrUserName = UserName
End Function

Function GetUser() As String
GetUser = PstrUserName
End Function
-----------------------------------------------------------------------------------



Any help would be a huge help .....................

cheers,

Mike
________
homemade vaporizers
 
Last edited:

Fizzio

Chief Torturer
Local time
Today, 21:50
Joined
Feb 21, 2002
Messages
1,885
It depends whether you want to pull the userID into the current record on the open form or another record somewhere else.

To pull it into the existing record, make sure you include the field in the form's recordsource then on the On_Click event of the button,
me.FieldtoUpdate = Forms!LogonForm!txtUserName
BUT you need to have the combo to include both the UserID and UserName (if they are the same field then it doesn't matter - but if not, you should link via their autonumber field if you have one).

The latter is a little more tricky as you will need to find the relevant record and then insert the new value.

I suspect you mean the former though.

HTH
 

mikebaldam

Registered User.
Local time
Today, 21:50
Joined
Oct 29, 2002
Messages
114
Still cant use the

me.FieldtoUpdate = Forms!LogonForm!txtUserName

to pull in the data I just get an error stating:

CANNOT FIND MACRO ME.



Any other ideas ???

(please)



Mike
________
GS550E
 
Last edited:

Fizzio

Chief Torturer
Local time
Today, 21:50
Joined
Feb 21, 2002
Messages
1,885
Sorry, should have been more clear. On the On_Click event of the button, choose [event procedure], click on the ... then enter the code there - it is VB code.

:eek:
 

mikebaldam

Registered User.
Local time
Today, 21:50
Joined
Oct 29, 2002
Messages
114
Cheers You're a star...........!!!!!!!



yeah its pulling the combo value but I reckon I can sort that one out..............


Its so simple when someone tells you how......



Cheers again



:D
________
Health Forums
 
Last edited:

Users who are viewing this thread

Top Bottom