Access 2013 - UserLonOn frm & security. RRS feed

  • Question

  • Hello i'm TobiasOlsson and i have a question to ask about logon forms and the associated VBA among with optimization and security. Which line of code do i need when i want to tell access that i want to compare one string with another string from a Table & Form. I have written an If statement that compares the strings but i do not know how i "call" the tabel, querys & forms i need in order to make the code work properly. I have a short description of my structure below, if it will help.

    If you have an answer i would appreciate if you could explain how the piece of code works part by part. Fore some reason do i always want to understand the code i write & how it should be used.


    I have made a Table & Form which will be used in this process.
    The tblEmplyees is the table which contains the users, UserName & Password. The frmLogOn is the form which will work as the LogOn form when a user want to access the database. The frmLogOn have on field for the userName, password, a logOn button & a label with an error message.

    The tbl & form Structure

    In the tblEmplyees:
     have 6 columns, SID (SecurityID), ClassType, FristName, LastName, UserName, Password.
    The SID is a autonumber & the Primary Key.
    The Class-Type determines if the user is a Administrator, Operator, Supervisor, Guest, Other or ("Dev").

    The frmLogOn:

    1. UserName field Name = txtUserName
    2. Password field Name = txtPassword
    3. LogOn button field Name = cmd_btn_LogOn
    4. Error message field Name = lbl_LogOnError


    txtUserName is compared with UserName from tblEmployees
    txtPassword is compared with Password from tblEmployees
    cmd_btn_LogOn triggers the event.
    lbl_LogOnError displays an error message if one of the needed conditions are "false" & resets the input fields.

    Structure Addons.

    ~I have had a second thought on how this procedure can work, it is just a thought.

    This is instead of compare the data directly from the necessary table, to protect it from circumlocutions.
    For an example, a query which hold the txtUserName & txtPassword inputs temporary, and a query which sorts the tblEmployees by lastName & userName. I believe this could be useful to speed up the search when the tblEmployees have grown to, say 30 to 100 Employees or more. Which means i would have to compare the temporary queries instead of compare the frmLogOn & tblEmployees directly.


    This is the code i have written so far.

    Private Sub cmd_btn_LogOn_Click()
    'Call functions
    'Personal prefix to add "input" when a user enter a string & or value.
    Dim txtUserName, txtPassword As String
        txtUserName = inputTxtUserName
        txtPassword = inputPassword
    Dim UserName, Password As String
    On Error GoTo ErrHandler
    If inputTextUserName = UserName Then                '1st_Comparison
         Me.lbl_LogOnError.Visible = False
        Else: inputTextUserName = UserName = False
         Me.lbl_LogOnError.Visible = True
         Exit Sub
        If inputTextPassword <> Password = True Then    '2nd_Comparison
            Me.lbl_LogOnError.Visible = True
            Exit Sub
            If inputTextPassword = Password Then        '3d_Comparison
                DoCmd.OpenForm "frmIndexMenu", acNormal
                'frmIndexMenu is the database head menu.
            End If
        End If
    End If
        Exit Sub
        msg Err.Description
        Resume ErrExit
    End Sub


    • Edited by TobiasOlsson Tuesday, June 2, 2015 12:46 PM code update.
    Tuesday, June 2, 2015 12:43 PM


All replies