need help to show user name (1 Viewer)

morteza76

New member
Local time
Today, 12:18
Joined
Jul 18, 2022
Messages
8
hello im new to access code so i have a login form and a user table that have the usernames , passwords and user full name and in my login form i have login button with this code:
Code:
Option Compare Database

Private Sub cmdlog_Click()
If IsNull(Form_frmlogin.txtuser) Then
MsgBox "enter user", vbInformation, "adam vorood"
Me.txtuser.SetFocus
Me.txtuser.BackColor = vbYellow
ElseIf IsNull(Form_frmlogin.txtpass) Then
MsgBox "enter pass", vbInformation, "adam vorood"
Me.txtpass.SetFocus
Me.txtpass.BackColor = vbYellow
ElseIf IsNull(DLookup("userName", "tbluser", "userName='" & Form_frmlogin.txtuser.Value & "' and userPass='" & Form_frmlogin.txtpass.Value & "'")) Then
MsgBox "nam ya ramz ghalate", vbInformation, "khata"
Else
DoCmd.OpenForm "frmmain"
DoCmd.Close acForm, "frmlogin", acSaveYes

End If


End Sub
so my question is how can i show my user full name after he login and goes to main form ? can i use tempvar? and how to use it?
 

Ranman256

Well-known member
Local time
Today, 03:48
Joined
Apr 9, 2015
Messages
4,337
Code:
sub btnSubmit_click()
dim vPass0
vPass0 =  dlookup("[password]","tUsers","[userid]='" & txtUser & "'")
if vPass0<> txtPass then
   msgbox "User Login or Password is invalid"
   exit sub
endif
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:48
Joined
May 7, 2009
Messages
19,249
Code:
Private Sub cmdlog_Click()
If IsNull(Form_frmlogin.txtuser) Then
    MsgBox "enter user", vbInformation, "adam vorood"
    Me.txtuser.SetFocus
    Me.txtuser.BackColor = vbYellow
    Exit Sub
End If
Me.txtuser.BackColor = vbWhite
If IsNull(Form_frmlogin.txtpass) Then
    MsgBox "enter pass", vbInformation, "adam vorood"
    Me.txtpass.SetFocus
    Me.txtpass.BackColor = vbYellow
    Exit Sub
End If
Me.txtpass.BackColor = vbWhite

If IsNull(DLookup("userName", "tbluser", "userName='" & Form_frmlogin.txtuser.Value & "' and userPass='" & Form_frmlogin.txtpass.Value & "'")) Then
    MsgBox "nam ya ramz ghalate", vbInformation, "khata"
    Exit Sub
End If
If IsNull([TempVars]![UserName]) Then
    TempVars.Add "UserName", ""
End If
'arnelgp
'save the username to Tempvars
'on main form add a Label/Textbox to show the Username
'on the Load event of frmMain add a code
'
' private sub form_load()
'     Me!label1.Caption = TempVars!UserName
' end sub
'
TempVars!UserName = Form_frmlogin.txtuser.Value
DoCmd.OpenForm "frmmain"
DoCmd.Close acForm, "frmlogin", acSaveYes
End Sub
 

morteza76

New member
Local time
Today, 12:18
Joined
Jul 18, 2022
Messages
8
Code:
Private Sub cmdlog_Click()
If IsNull(Form_frmlogin.txtuser) Then
    MsgBox "enter user", vbInformation, "adam vorood"
    Me.txtuser.SetFocus
    Me.txtuser.BackColor = vbYellow
    Exit Sub
End If
Me.txtuser.BackColor = vbWhite
If IsNull(Form_frmlogin.txtpass) Then
    MsgBox "enter pass", vbInformation, "adam vorood"
    Me.txtpass.SetFocus
    Me.txtpass.BackColor = vbYellow
    Exit Sub
End If
Me.txtpass.BackColor = vbWhite

If IsNull(DLookup("userName", "tbluser", "userName='" & Form_frmlogin.txtuser.Value & "' and userPass='" & Form_frmlogin.txtpass.Value & "'")) Then
    MsgBox "nam ya ramz ghalate", vbInformation, "khata"
    Exit Sub
End If
If IsNull([TempVars]![UserName]) Then
    TempVars.Add "UserName", ""
End If
'arnelgp
'save the username to Tempvars
'on main form add a Label/Textbox to show the Username
'on the Load event of frmMain add a code
'
' private sub form_load()
'     Me!label1.Caption = TempVars!UserName
' end sub
'
TempVars!UserName = Form_frmlogin.txtuser.Value
DoCmd.OpenForm "frmmain"
DoCmd.Close acForm, "frmlogin", acSaveYes
End Sub
Tnx bro and one more q how can i show it in main menu with a boundtex?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:48
Joined
May 7, 2009
Messages
19,249
main menu with a boundtex
you mean Unbound textbox?
same, add code to the main form's Load Event:

private sub Form_Load()
Me!UnboundTextbox = Tempvars!UserName
end sub
 

morteza76

New member
Local time
Today, 12:18
Joined
Jul 18, 2022
Messages
8
sorry again i put the code in button and that one in main form load event but it doesnt work why?
 

morteza76

New member
Local time
Today, 12:18
Joined
Jul 18, 2022
Messages
8
and i dont want to show the user name in user table i have
username
userpassword
usershowname
i want to show usershowname in main menu
 

morteza76

New member
Local time
Today, 12:18
Joined
Jul 18, 2022
Messages
8
Code:
Private Sub cmdlog_Click()
If IsNull(Form_frmlogin.txtuser) Then
    MsgBox "enter user", vbInformation, "adam vorood"
    Me.txtuser.SetFocus
    Me.txtuser.BackColor = vbYellow
    Exit Sub
End If
Me.txtuser.BackColor = vbWhite
If IsNull(Form_frmlogin.txtpass) Then
    MsgBox "enter pass", vbInformation, "adam vorood"
    Me.txtpass.SetFocus
    Me.txtpass.BackColor = vbYellow
    Exit Sub
End If
Me.txtpass.BackColor = vbWhite

If IsNull(DLookup("userName", "tbluser", "userName='" & Form_frmlogin.txtuser.Value & "' and userPass='" & Form_frmlogin.txtpass.Value & "'")) Then
    MsgBox "nam ya ramz ghalate", vbInformation, "khata"
    Exit Sub
End If
If IsNull([TempVars]![UserName]) Then
    TempVars.Add "UserName", ""
End If
'arnelgp
'save the username to Tempvars
'on main form add a Label/Textbox to show the Username
'on the Load event of frmMain add a code
'
' private sub form_load()
'     Me!label1.Caption = TempVars!UserName
' end sub
'
TempVars!UserName = Form_frmlogin.txtuser.Value
DoCmd.OpenForm "frmmain"
DoCmd.Close acForm, "frmlogin", acSaveYes
End Sub
can u help bro
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:48
Joined
Sep 21, 2011
Messages
14,607
You are using DLookUp() for username, do the same for showname. ?
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:48
Joined
Sep 21, 2011
Messages
14,607
Look at the code as to how you do one and do the same for the other.
If you do not know the syntax, google and look at the ms doc link.
That is what I do.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:48
Joined
May 7, 2009
Messages
19,249
see this demo.
 

Attachments

  • demo_login.accdb
    1.6 MB · Views: 155

Garcimat

Member
Local time
Today, 17:48
Joined
Jun 7, 2022
Messages
67
I am doing it on my system as well, but I am using a global variable in a module that I call back every time I need the user name.
 

Users who are viewing this thread

Top Bottom