Okay, let me try to explain how I did this.
Firstly, I have an unbound form names Sys_frmLogin. The user types in their User Name and Password (txtUserName & txtPassword). These two fields are linked to a sub form which is set to Visible = False. The subform is bound to the Sys_tblUser table which records all active users, user names, passwords and access rights etc.
txtUserName & txtPassword are the master fields to the linked child fields in the sub form. Therefore, if the user types in the correct UN and Pwd, then the subform will populate. If the subform recordset is 0, I display a message box informing the user that their UN and/or Pwd is wrong & increment a counter - at a system defined number, the user is locked from further login attempts to prevent a hacker from guessing all day!!!
The <Login> command button then enables, the user clicks the cmdLogin button and this sets the form to Visible = False. This means that the form is active and that the fields can be referenced.
Sys_frmLogin references certain fields from the subform such as;
UserAccessLevel (all records, owned records etc)
ModuleAccessRights
UserRole (Admin, user, developer etc)
Each main level screen interrogates Sys_frmLogin to check what options to display and what query to execute. E.g.
Attached to the OnOpen Event
Dim Whatever needs dimming
Select Case UserAccessLevel
Case 1
Me.ResourdSource = “Insert SQL Query here;”
Me.Module1.Visible = True
Me.Module2.Visible – False
Etc.
Case 2
Me.ResourdSource = “Insert SQL Query here that queries only the records owned by the user;”
Me.Module1.Visible = False
Me.Module2.Visible – True
Etc.
End Select
Hope that this helps explain. I am playing with creating a global class module that takes the login variables and these are referenced rather than the invisible form. It just sounds more efficient that way, but the first model works great for me.
I haven't failed, I have just found 10,000 ways that it won't work!