Results 1 to 6 of 6
  1. #1
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93

    String Literacy with Quotation Issue

    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...

  2. #2
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Anyone?

    I am continuing to have an issue with the highlighted part of the code. How can I verify that the field [Active] has a value of 1 (the checkbox is checked) and then the code will proceed to execute.

    Help will be appreciated!

    The 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
    Last edited by excellenthelp; 07-31-2014 at 06:21 AM.

  3. #3
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Try "True" or "Yes" instead of 1.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I think this line is an issue.

    rst.FindFirst "UserID = '" & Me.txtUser & "'" And "Active = 1"

    try
    rst.FindFirst "UserID = '" & Me.txtUser & "' And Active = -1"

  5. #5
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    At last it works! -___-

    The code is:
    Code:
    rst.FindFirst "UserID = '" & Me.txtUser & "'" & "And Active = -1"
    It only needed a negative sign when I was overly obsessing on 0 and 1. Duh!

    Thank you everyone for responding and for this, you get a reputation star each!

    Marking this as SOLVED.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Glad you have it solved.

    But this was also required in your original
    rst.FindFirst "UserID = '" & Me.txtUser & "'"& "And Active = -1"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Quotation/Proposal Database Template
    By MikeH in forum Database Design
    Replies: 1
    Last Post: 07-11-2014, 12:35 PM
  2. InStr() and quotation marks
    By Puebles in forum Programming
    Replies: 3
    Last Post: 11-22-2013, 07:36 AM
  3. Quotation Mark Hell
    By shurstgbr in forum Programming
    Replies: 4
    Last Post: 06-13-2011, 06:17 AM
  4. Issue Using Replace in SQL String
    By starryNight in forum Programming
    Replies: 15
    Last Post: 06-03-2011, 01:24 PM
  5. Concatenate Quotation Marks
    By millerdav99 in forum Programming
    Replies: 3
    Last Post: 04-11-2011, 09:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums