I am using this code for user loging but user form remains opened at back end.
How this form can be closed automatically after successful login.
Code:
Private Sub cmdOk_Click()On Error GoTo Err_cmdOk_Click
'-----------------------------------------------------------------------------------------------------------------------------
' This code is used to validate users found in the tblSecurity table. If the wrong user name or password is
' provided access is denied.
' Created by: Liam Sullivan
' Date Created: 08 Jan 2012
' Date Modified: 08 Jan 2012
'-----------------------------------------------------------------------------------------------------------------------------
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblSecurity", dbOpenDynaset)
If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID = '" & Me.txtUser & "'"
If rst.NoMatch Then
MsgBox "You entered an incorrect Username or Password." & Chr(13) & _
"Please enter the correct Username and Password or " & Chr(13) & _
"contact the Administrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
ElseIf Me.txtPassword = "password" Then
MsgBox "This is the first time you've logged in or your password has been reset." & Chr(13) & _
"You must change your password before you can log in.", _
vbOKOnly + vbExclamation, "Change Password"
stDocName = "frmUserLogonNew"
stLinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "Mainmenu"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
MsgBox "You have left the Username and/or Password blank." & Chr(13) & _
"Please enter the correct Username and Password or " & Chr(13) & _
"contact the Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
End If
With User
.AccessID = rst.Fields("AccessID")
.ViewID = rst.Fields("ViewID")
.Active = rst.Fields("Active")
.Password = rst.Fields("Password")
.SecurityID = rst.Fields("SecurityID")
.UserID = rst.Fields("UserID")
End With
rst.Close
Exit_cmdOk_Click:
Exit Sub
Err_cmdOk_Click:
MsgBox Err.Description
Resume Exit_cmdOk_Click
End Sub