Results 1 to 3 of 3
  1. #1
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124

    How do I filter forms based on Section?

    Hello,
    Forum

    I am trying to do an Inventory database and I have to complete it by next week.
    I am refering to Inventory 2007 Template
    I am using microsoft access 2016 to design my db

    I have a question.

    I would like to have a login form in the biggining when the db opens.
    I would like to filter the search by employee's section.

    For all of my subsequent forms.

    How can I go about doing it?

    Any help will be much appreciated.



    Yours Sincerely,
    Haziq
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you make a login form with text boxes for UserID, Password, Domain.
    I have a tUser table to store the IDs of those allowed in the system.(it does not store passwords)

    1.check if user is in the tUser table
    2.check with windows authentication. If they pass both, show the menu, else quit.

    Code:
    public gvUserID , gvUSerGroup
    
       'form code
    '-------------
    Private Sub btnLogin_Click()
    '-------------
    Dim sUser As String, sPass As String, sDom As String
    dim vDbID
    
    
    sUser = txtUser
    sPass = txtPass
    sDom = txtDom
    
    
    gvUserID = Environ("Username")
    vDbID = Dlookup("[userId]","tUsers","[UserID]='" & vID & "'"
    gvUSerGroup = Dlookup("[Group]","tUsers","[UserID]='" & vID & "'"
    
    
    if ucase(gvUserID) = ucase(vDbID) then
      If WindowsLogin(sUser, sPass, sDom) and vID = vDbID Then
       mbSafe = True
       DoCmd.OpenForm "frmMainMenu"
       DoCmd.OpenForm "frmLogin"
       DoCmd.Close
      Else
        MsgBox "LOGIN INCORRECT", vbCritical, "Bad userid or password"
      End If
    else
       MsgBox "You are not registered for this db.", vbCritical, "Contact Admin"
    endif
    End Sub
    
    
    
    
    '-------------
    Public Function WindowsLogin(ByVal strUserName As String, ByVal strpassword As String, ByVal strDomain As String) As Boolean
    '-------------
            'Authenticates user and password entered with Active Directory.
    
    
            On Error GoTo IncorrectPassword
            
            Dim oADsObject, oADsNamespace As Object
            Dim strADsPath As String
            
            strADsPath = "WinNT://" & strDomain
            Set oADsObject = GetObject(strADsPath)
            Set oADsNamespace = GetObject("WinNT:")
            Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strDomain & "\" & strUserName, strpassword, 0)
            
            WindowsLogin = True    'ACCESS GRANTED
            
    ExitSub:
            Exit Function
            
    IncorrectPassword:
            WindowsLogin = False   'ACCESS DENIED
            Resume ExitSub
    End Function







    once the user gets thru the login screen, the main menu (or other form) opens then
    turn /on off buttons depending on the group.
    An invisible text box is set to the user group so now all queries for that form pull only data.
    Here UserGroup 'A' = admin, who has rights to see everything.
    The queries would look at the txt box to allow only that group.

    Code:
    sub form_load()
    
    txtGroup = gvUserGroup
    btnAdmin.enabled = gvUserGroup = "A"
    
    if gvUserGroup = "A" then
       me.recordsource = "qsDataAll"
    else
       me.recordsource = "qsDataByGroup"
    endif
    end sub

  3. #3
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    Thanks Runman256 for the code.

    I will try it out

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

Similar Threads

  1. Forms and Writing in Their Notes Section
    By Lou_Reed in forum Access
    Replies: 8
    Last Post: 12-22-2016, 08:14 AM
  2. Replies: 5
    Last Post: 05-12-2014, 09:43 AM
  3. Replies: 2
    Last Post: 01-09-2014, 07:24 PM
  4. Replies: 6
    Last Post: 03-26-2013, 12:17 PM
  5. Replies: 3
    Last Post: 07-08-2011, 05:48 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