Results 1 to 11 of 11
  1. #1
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181

    Syntax error

    I have been messing around with my code when the user logs in. I was watching a video by Steve Bishop and found this very informative. I followed the video to the letter and created the code for my login form. All worked well until i shut down Access and started it again and got the following error message.Click image for larger version. 

Name:	Public Function.PNG 
Views:	33 
Size:	5.7 KB 
ID:	31470


    I wrote the module code as instructed, see below

    Module code

    UserAccess = Nz(DLookup("HasAccess", "tblEmployeeAccess", "AccessType=" & TempVars("AccessType") & " AND FormName='" & FormName & "'"), False)
    And now when I login the error message points to this line of code

    Code behind login button

    Dim rs As Recordset

    Set rs = CurrentDb.OpenRecordset("Login", dbOpenSnapshot, dbReadOnly)
    rs.FindFirst "UserLogin ='" & Me.txtLoginID & "'"

    If rs.NoMatch = True Then
    Me.lblWrongUserName.Visible = True
    Me.txtLoginID.SetFocus
    Exit Sub
    End If
    Me.lblWrongUserName.Visible = False

    If rs!Password <> Nz(Me.txtPassword, "") Then
    Me.lblWrongPassword.Visible = True
    Me.txtPassword.SetFocus
    Exit Sub
    End If
    Me.lblWrongPassword.Visible = False
    DoCmd.OpenForm "frmMenu"
    DoCmd.Close acForm, "frmLogin"

    TempVars("AccessType") = rs!AccessType.Value

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    FormName and AccessType are fields in table? How do you populate the variable FormName? Maybe:

    " AND FormName = '" & Me.Name & "'"

    I've never used TempVars. Where are setting the variable AccessType?

    Want to provide link to that video?
    Last edited by June7; 11-30-2017 at 05:26 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    If I enlarge the tiny picture, I see the expression has a syntax error, which looks like you're losing the tempVars value. The expression seems to evaluate to
    "AccessType = AND formName = ..." so something's missing before the AND.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by hinchi1 View Post
    I have been messing around with my code when the user logs in. I was watching a video by Steve Bishop and found this very informative. I followed the video to the letter and created the code for my login form.
    Actually you didn't "follow the video to the letter" or you changed the code. You changed some object names.

    Steve Bishop Video



    Since you modified the code, what's up with
    Code:
    Module code
    
        UserAccess = Nz(DLookup("HasAccess", "tblEmployeeAccess",   "AccessType=" & TempVars("AccessType") & " AND FormName='"  &  FormName & "'"), False)
    
    and
    
    TempVars("AccessType") = rs!AccessType.Value
    Where/how are they used in your dB???




    --------------------------------------------------------------------------------------
    (and I have issues with the SB code - the record set was not closed and the rs object was not destroyed - see my code modifications)
    How I modified the code:
    Code:
    Private Sub btnLogin_Click()
        Dim rs As Recordset
    
        Set rs = CurrentDb.OpenRecordset("tbl1Employees", dbOpenSnapshot, dbReadOnly)
    
        rs.FindFirst "UserName='" & Me.txtUserName & "'"
    
        If rs.NoMatch = True Then
            Me.lblWrongUser.Visible = True
            Me.txtUserName.SetFocus
    
        Else
            Me.lblWrongUser.Visible = False
    
            If rs!Password <> Nz(Me.txtPassword, "") Then
                Me.lblWrongPass.Visible = True
                Me.txtPassword.SetFocus
    
            Else
                Me.lblWrongPass.Visible = False
                DoCmd.OpenForm "frmMain"
                DoCmd.Close acForm, "frmLogin"
            End If
        End If
    
        rs.Close
        Set rs = Nothing
    End Sub
    Last edited by ssanfu; 11-30-2017 at 11:13 PM.

  5. #5
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    Quote Originally Posted by ssanfu View Post
    Actually you didn't "follow the video to the letter" or you changed the code. You changed some object names.

    Steve Bishop Video



    Since you modified the code, what's up with
    Code:
    Module code
    
        UserAccess = Nz(DLookup("HasAccess", "tblEmployeeAccess",   "AccessType=" & TempVars("AccessType") & " AND FormName='"  &  FormName & "'"), False)
    
    and
    
    TempVars("AccessType") = rs!AccessType.Value
    Where/how are they used in your dB???






    --------------------------------------------------------------------------------------
    (and I have issues with the SB code - the record set was not closed and the rs object was not destroyed - see my code modifications)
    How I modified the code:
    Code:
    Private Sub btnLogin_Click()
        Dim rs As Recordset
    
        Set rs = CurrentDb.OpenRecordset("tbl1Employees", dbOpenSnapshot, dbReadOnly)
    
        rs.FindFirst "UserName='" & Me.txtUserName & "'"
    
        If rs.NoMatch = True Then
            Me.lblWrongUser.Visible = True
            Me.txtUserName.SetFocus
    
        Else
            Me.lblWrongUser.Visible = False
    
            If rs!Password <> Nz(Me.txtPassword, "") Then
                Me.lblWrongPass.Visible = True
                Me.txtPassword.SetFocus
    
            Else
                Me.lblWrongPass.Visible = False
                DoCmd.OpenForm "frmMain"
                DoCmd.Close acForm, "frmLogin"
            End If
        End If
    
        rs.Close
        Set rs = Nothing
    End Sub
    I will go through the video again today. i am using this code to try and disable certain buttons for users who will not have permissions to edit or add new data. The can only view the data. Thanks for all you feedback, as ever greatly appreciated.

  6. #6
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    I believe the error is caused by this line in the form load event of my frmMenu as i am trying to either disable or hide command buttons to limit user access.

    Code:

    Me.cmdOpenPGR.Visible = modGlobal.UserAccess("frmPGRDeskDataEntry1")

    if i comment this code out and the user click on the button to open "frmPGRDeskDataEntry1" they do get a message saying they don't have access to the form. So this part works. it is just when i want to hide or disable the command button is where the problem lies. i will go through the video again. For reference i have changed object names to match the names of the objects in my database. Thanks again.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Steve Bishop's video on creating a login screen has nothing to do with setting the visible property of buttons.


    It would be a lot easier to make suggestions if the dB was available.

    Code:
    Me.cmdOpenPGR.Visible = modGlobal.UserAccess("frmPGRDeskDataEntry1")
    If modGlobal is the name of a standard module, the syntax of the line of code above is incorrect. Should not be referencing the module name.
    Not sure what "UserAccess" is..... is it a function? A variable?
    If a function, what is the code?
    If a (global) variable, how is it filled?


    What is the code for the form load event of the form "frmMenu"?

  8. #8
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    I watched his video on managing user access. This involves code behind the login screen and then he demonstrates 3 ways to restrict user access to a form.
    1. Prevent user from opening form in the objects pane.
    2. Code behind a button to prevent user access to a form and 3
    Hide the command button so the user has no way what so ever to access a restricted form.

    I will watch the video again today and see what I have missed. Thanks again for your feedback.

  9. #9
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    I have been through the video again and cannot see what i am doing wrong, very frustrating.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Post a copy of your database as ssanfu suggested.

  11. #11
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181

    Syntax Error

    Quote Originally Posted by orange View Post
    Post a copy of your database as ssanfu suggested.
    I found that i could not apply code to my main form but i could to other subsequent forms. not ideal but it works for me. Thanks for all your inputs.

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

Similar Threads

  1. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  2. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  3. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 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