Hello house
Hello experts
I have been trying for months to get my login form to open up to a specific record on the main form(NOTE PLS my main form is called "Navigation Form"). I have a table that store (ID, name, sex, country, Address etc) which i used to create my main form.
I also have a table called tblUser which stores (ID, password and login name.) I built a login form that allows the user to type in their password and login name.
I am attaching the file. My aim is to get user login
form to display a particular record on the main form
The code only display first record ID (1) of the main form when login.
PLS what will be added to the code to enable a specific form to open after login.
Am not that good in writing vba code. Pls help me out
Option Compare Database
Private Sub Command1_Click()
Dim User As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim UserName As String
Dim TempID As String
If IsNull(Me.txtUserName) Then
MsgBox "Please enter UserName", vbInformation, "Username required"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Password required"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid Username or Password!"
Else
TempID = Me.txtUserName.Value
UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please change Password", vbInformation, "New password required"
DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
Else
'open different form according to user level
If UserLevel = 1 Then ' for admin
DoCmd.OpenForm "Admin Form"
Else
DoCmd.OpenForm "Navigation Form"
End If
End If
End If
End If
End Sub
Private Sub Form_Load()
Me.txtUserName.SetFocus
End Sub
Hello experts
I have been trying for months to get my login form to open up to a specific record on the main form(NOTE PLS my main form is called "Navigation Form"). I have a table that store (ID, name, sex, country, Address etc) which i used to create my main form.
I also have a table called tblUser which stores (ID, password and login name.) I built a login form that allows the user to type in their password and login name.
I am attaching the file. My aim is to get user login
form to display a particular record on the main form
The code only display first record ID (1) of the main form when login.
PLS what will be added to the code to enable a specific form to open after login.
Am not that good in writing vba code. Pls help me out
Option Compare Database
Private Sub Command1_Click()
Dim User As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim UserName As String
Dim TempID As String
If IsNull(Me.txtUserName) Then
MsgBox "Please enter UserName", vbInformation, "Username required"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Password required"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid Username or Password!"
Else
TempID = Me.txtUserName.Value
UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please change Password", vbInformation, "New password required"
DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
Else
'open different form according to user level
If UserLevel = 1 Then ' for admin
DoCmd.OpenForm "Admin Form"
Else
DoCmd.OpenForm "Navigation Form"
End If
End If
End If
End If
End Sub
Private Sub Form_Load()
Me.txtUserName.SetFocus
End Sub