Hello first of all I explain what I have in my hands.
Two masks, in
mask A, there is the
"user" field and other fields (what interests me is
"user"). While in
Mask B it would be the
login, with username and password.
When I enter a
User in
Mask A, I automatically open the Login Form with which I identify who accesses. In this way I would like to take (when the credentials are entered correctly) username of the person who logs in and put it with
"User" in
Mask A.
I created a global variable
"Username1".
This is the code I did test and the message I used to understand works. But I can not use it by putting it in the box I would like.
Private Sub Employee_AfterUpdate()
DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1
End Sub
This is the global variable.
Option Compare Database
Option Explicit
Public username1 As String
I hope I explained myself. Thank you
Code of Login
Private Sub Command0_Click()
DoCmd.CloseDatabase
End Sub
Private Sub Command1_Click()
If IsNull(Me.tb_ID) Or IsNull(Me.tb_pwd) Then
MsgBox "You must enter password or login ID.", vbOKOnly + vbInformation, "Required Data"
Me.tb_ID.SetFocus
Exit Sub
End If
If Me.tb_pwd.Value = DLookup("[psw]", "Utenti", "[User]='" & Me.tb_ID.Value & "'") Then
username1 = Me.tb_ID.Value
DoCmd.Close acForm, "login", acSaveNo
DoCmd.OpenForm "Work Hours List"
Else
MsgBox "Password or login ID incorrect. Please Try Again", vbOKOnly + vbExclamation, "Invalid Entry!"
Me.tb_pwd.SetFocus
End If
End Sub
Code of what i tried with the field Employee
Private Sub Employee_AfterUpdate()
DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1
End Sub
Private Sub Form_Close()
DoCmd.OpenForm "login"
End Sub
What I have tried:
Private Sub Employee_AfterUpdate()
DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1
End Sub
Private Sub Form_Close()
DoCmd.OpenForm "login"
End Sub
Private Sub EmployeeText_AfterUpdate()
DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1
Me.EmployeeText.Value = username1
End Sub