Results 1 to 6 of 6
  1. #1
    aliaslamy2k is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Apr 2020
    Posts
    31

    Restrict user access

    Hello Experts,


    I want to ammend below VBA in a way that it should check the user name and open
    the form accordingly. Below is the code i got from google, but it works only for one form.

    Example:


    If user : Abalkhair log-in then he should be able to see only form ABC1




    Private Sub BtnLogin_Click()
    Dim rs As Recordset

    Set rs = CurrentDb.OpenRecordset("Login", dbOpenSnapshot, dbReadOnly)


    rs.FindFirst "UserName='" & Me.TxtUserName & "'"

    If rs.NoMatch = True Then
    Me.LblWrongUser.Visible = True
    Me.TxtUserName.SetFocus
    Exit Sub
    End If
    Me.LblWrongUser.Visible = False




    If rs!Password <> Me.TxtPassword Then
    Me.LblWrongPass.Visible = True
    Me.TxtPassword.SetFocus
    Exit Sub
    End If
    Me.LblWrongPass.Visible = False
    DoCmd.OpenForm "Report Form"
    DoCmd.Close acForm, Me.NAME

    End Sub
    Attached Thumbnails Attached Thumbnails Capture.JPG   Capture1.JPG  

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,736

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,119
    Have a look at my free utility http://forestbyte.com/ms-access-util...access-levels/

    Not quite sure what you wanted to achieve with your code as it will not affect any object in your db, but if you want to open a specific form for each user you need to change this line
    Code:
     DoCmd.OpenForm "Report Form"
    to this
    Code:
     DoCmd.OpenForm rs("FormName")
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    aliaslamy2k is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Apr 2020
    Posts
    31
    Dear Gicu,

    Thank you so much. i changed the code as per your suggestion and its working great.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,119
    Great to hear, good luck with your project!

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Here is a link on how to offer permissions throughout an Access Data Base. In this tutorial, you can make certain forms available to certain people and restrict all others.

    https://www.mrexcel.com/board/thread...system.248191/

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

Similar Threads

  1. Replies: 7
    Last Post: 03-27-2018, 06:07 AM
  2. Replies: 2
    Last Post: 08-04-2017, 12:48 PM
  3. Replies: 2
    Last Post: 01-16-2015, 06:43 PM
  4. Restrict user to navigation form
    By Whelt in forum Access
    Replies: 3
    Last Post: 04-22-2012, 06:19 PM
  5. Restrict form access to certain people
    By DannyBoy7783 in forum Forms
    Replies: 2
    Last Post: 06-09-2008, 06:18 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