need help to show user name

morteza76

New member
Local time
Today, 09:03
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?
 
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
 
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
 
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?
 
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
 
sorry again i put the code in button and that one in main form load event but it doesnt work why?
 
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
 
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
 
You are using DLookUp() for username, do the same for showname. ?
 
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.
 
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

Back
Top Bottom