Hello Accessers,
I am struggling with writing this line of code to grant access to users if they are marked as active. This is based on one table with two fields:
Table: tblUsers
Field1: UserID (Textbox type)
Field2: Active (Checkbox type)
The code works fine without the red highlighted part of the code. After attempting to add the verification of whether or not if the user is active after verifying its User ID. I suspect it is something to do with my lame writing of the quoting part of the code.
The code is:
Code:
rst.FindFirst "UserID = '" & Me.txtUser & "'" And "Active = 1"
The code is written by Liam Sullivan and I want to give him/her credit for this. I am posting the whole code below that I am using in this thread:
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("tblSecurityUsers", dbOpenDynaset)
If Not IsNull(Me.txtUser) Then
rst.FindFirst "UserID = '" & Me.txtUser & "'" And "Active = 1"
If rst.NoMatch Then
MsgBox "Access Denied." & Chr(13) & _
"Please contact the Administrator for assistance.", vbOKOnly + vbCritical, "Access Denied"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "frmSplashScreen"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
MsgBox "Your Username is not detected." & Chr(13) & _
"Please contact the Administrator for assistance. ", vbOKOnly + vbCritical, "Access Denied"
End If
With User
.AccessID = rst.Fields("AccessID")
.ViewID = rst.Fields("ViewID")
.Active = rst.Fields("Active")
.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
Any help will be appreciated!
Thanks...