Session recording

chrisguk

Registered User.
Local time
Today, 09:09
Joined
Mar 9, 2011
Messages
148
Hi guys.

I am using a great login solution that was made by DCrake. I have attached the database to this post for you to see.

My problem is understanding how to implement access levels on each form. At the bottom of any given form I want it to show the name of the user and when the form opens to check the permissions level table to see if they are allowed access to that form.

I know there is a way to do this using Globals and declaring the session but cant figure it out at all.

Any help with this would be fantastic.

Thanks
 

Attachments

Code:
Private Sub Form_Load()
'/Access restricted to admin users only
If intAccessLevel <> 3 Then
    MsgBox "Access to this option is restricted to admin users only", vbExclamation + vbOKOnly, "Access Denied"
    DoCmd.Close
    
    Exit Sub
End If

End Sub

Try pasting the above into the sessions form. As this form is usually retricted to admin users only none admin users can open it.
 
Hi There,

Thank you DCrake for your assistance, it does work nicely. I have a little issue though.
When it denies access to the user the form still opens thus allowing them access. I have pasted my interpretation of the code below, is there anything I have done wrong here?

Code:
Private Sub Form_Load()
   On Error GoTo Err_Form_Load
   '/Access restricted to admin users only
    If intAccessLevel <> 3 Then
    MsgBox "You do not have permission to access this area. If you believe you should have access then contact your Administrator", vbExclamation + vbOKOnly, "Access Denied"
    DoCmd.Close
    DoCmd.OpenForm "frmsites", acNormal, , , acFormEdit, acWindowNormal
    
    Else
    
    MsgBox "Success"
    DoCmd.RunMacro "mcrHide"
    DoCmd.Close acForm, "frmnav", acSaveNo
    Query_counter = 0
    Counter_txt = qrycounter
    qrycounter = DCount("[Logid]", "tbllog", "[tbllog].[sitesid] = [Forms]![frmsites]![sitesid]")
    Counter_txt = qrycounter
    End If
    
Exit_Form_Load:
    Exit Sub
    
Err_Form_Load:
    MsgBox "Sorry there is an error with this area.  Please report it to your Administrator"
    Resume Exit_Form_Load

End Sub
 
So what is happening that should not be happening?
 
So what is happening that should not be happening?


Hi,

I open frmlog from frmsites, when I click the button named frmlog if I am denied access the appropriate message box appears and states i am denied access. When I click ok the dialog box disappears and the frmlog still opens.
 
try

Code:
    DoCmd.Close "FrmLog"
    DoCmd.OpenForm "frmsites", acNormal, , , acFormEdit, acWindowNormal
    Exit Sub
 
try

Code:
    DoCmd.Close "FrmLog"
    DoCmd.OpenForm "frmsites", acNormal, , , acFormEdit, acWindowNormal
    Exit Sub

Hi Mr Crake,

Its still not working. I have pasted the revised code below:

Code:
Private Sub Form_Load()
   On Error GoTo Err_Form_Load
   '/Access restricted to admin users only
    If intAccessLevel <> 3 Then
    MsgBox "You do not have permission to access this area. If you believe you should have access then contact your Administrator", vbExclamation + vbOKOnly, "Access Denied"
    DoCmd.Close "frmlog"
    DoCmd.OpenForm "frmsites", acNormal, , , acFormEdit, acWindowNormal
    Else
    
    MsgBox "Success"
    DoCmd.RunMacro "mcrHide"
    Query_counter = 0
    Counter_txt = qrycounter
    qrycounter = DCount("[Logid]", "tbllog", "[tbllog].[sitesid] = [Forms]![frmsites]![sitesid]")
    Counter_txt = qrycounter
    End If
    
Exit_Form_Load:
    Exit Sub
    
Err_Form_Load:
    MsgBox "Sorry there is an error with this area.  Please report it to your Administrator", vbExclamation + vbOKOnly, "System Error"
    Resume Exit_Form_Load

End Sub

If you would like me to send you a copy of the database by email to make it easier then I am more than happy to do that if you pm me an email addy.
 
Just to prove the functionality

Design form frmNav
Select control Lable10
Edit the On Click event procedure

paste in the following code

Code:
'/Access restricted to admin users only
If intAccessLevel <> 3 Then
    MsgBox "Access to this area is restricted to admin users only", vbExclamation + vbOKOnly, "Access Denied"
    
    Exit Sub
Else
    Msgbox "you have admin rights"
    '/do something here...
End If

Save the form and log in with a user that doe snot have access level 3
Then click on the central label. (This could be a secret door to your admin tools)
 
This does not work as expected.

When you click on that label I agree it does bring up a message box stating you have been denied access to that area. But when you click ok to acknowledge that message it still continues to execute the command and open the desired form.

The example I used was to initially navigate to frmsites, this is the primary area in a sense. Then select creat query which is "frmlog". That demonstrates the same behaviour as above in that when you are told that access is denied it still alllows the code to execute and proceeds to open the form.

Hope that helps
 
The reason why it was happening is that you had hyperlink sub-addresses set up on all of the labels on your frmnav form so it ignored everyhting else. You need to program the events via the on click event .
 
Hi there,

I have posted with this reply an updated version of the database without the hyperlinks.

Just to clarify I wanted access restriction to work when navigating from frmsites to frmlog using the Create Query button located on the top right of frmsites.

The bahaviour that I get is that if I am denied access it gives me the appropriate dialog box stating I have been denied. The it closes the form and reopens that form I have been denied access to, thus actually allowing me access afterall. What it is suppose to do is stop the form execution and just go back to frmsites.

Sorry about this, any ideas?
 

Attachments

This would be the revised syntax for the on click event of the new query command button

Code:
If intAccessLevel < 3 Then
    MsgBox "You do not have access rights to create a new query", vbExclamation + vbOKOnly, "Acces Denied"
    Exit Sub
End If

Dim stDocName As String
Dim stLinkCriteria As String

    stDocName = "frmlog"
    DoCmd.OpenForm stDocName, , , , acFormAdd
    Forms![frmlog]![sitesid] = Forms![frmsites]![sitesid]
    DoCmd.Close acForm, "frmsites", acSaveYes

What does concerm me greatly is that there is no way to return to the previous frmNav menu from the forms as they all quit the data base instead of having a close form option.
 
This would be the revised syntax for the on click event of the new query command button

Code:
If intAccessLevel < 3 Then
    MsgBox "You do not have access rights to create a new query", vbExclamation + vbOKOnly, "Acces Denied"
    Exit Sub
End If
 
Dim stDocName As String
Dim stLinkCriteria As String
 
    stDocName = "frmlog"
    DoCmd.OpenForm stDocName, , , , acFormAdd
    Forms![frmlog]![sitesid] = Forms![frmsites]![sitesid]
    DoCmd.Close acForm, "frmsites", acSaveYes

What does concerm me greatly is that there is no way to return to the previous frmNav menu from the forms as they all quit the data base instead of having a close form option.

Thanks man, I will make those changes. I will also look to make some changes to incorporate a close form button too.

I will let you know what happens
 
It worked !!!!!!!!

Thank you so much, I appreciate your help :):D
 
Good to see we are making progress at last:)
 

Users who are viewing this thread

Back
Top Bottom