Security Roles Help

KLahvic01

Registered User.
Local time
Today, 04:02
Joined
May 3, 2012
Messages
80
I have a login page on my database where in order to gain access you need a user name and password. Each user name has a security level assigned to it which I would like to have dictate what parts of the database are available, I have the code working for my main form which opens after successful login, using a DLookup function, based on the login certain navigation buttons are enabled and some are not, etc. but when I try to navigate from the main screen to a new screen with different rules I get an error message saying it cant find the form frmlogin.

I am wondering if it is because I have to somehow store the current login in a temporary table or something to reference back to. Any help would be appreciated.

Thank you in advance,

KJ
 
Check the spelling of the form against your code.

And what is the code that fails?
 
I figured it would be helpful to see the code I am using. This works on my Main form in the OnCurrent Event:


Code:
If DLookup("[SecurityLevelID]", "tblLogins", "[UsersID] = " & Forms!frmLogin!cbousersel) = 1 Then
        Me.cmdtablemaint.Enabled = True
        Me.cmdaddnewuser.Enabled = True
        Me.cmdaddnewproduct.Enabled = True
        Me.cmdreceiving.Enabled = True
        Me.cmdreturns.Enabled = True
        Me.cmdreports.Enabled = True
        Me.cmdaddnewsupplier.Enabled = True
        Me.cmdopportunities.Enabled = True
        Me.cmdopportunitylist.Enabled = True
        Me.cmdaccounts.Enabled = True
        Me.cmdtransactions.Enabled = True
        Me.cmdcashsales.Enabled = True
        Me.cmdemployeelist.Enabled = True
        Me.cmdcustomerlist.Enabled = True
        Me.cmdaddnewcustomer.Enabled = True
        Me.cmdaddnewemployee.Enabled = True
 
vbaInet -

I get a runtime error and then when I debug, this is what is highlighted, incidently it is the same code that is on my other form that works.

Code:
If DLookup("[SecurityLevelID]", "tblLogins", "[UsersID] = " & Forms!frmLogin!cbousersel) = 1 Then

Not sure why this is different, again I thought maybe it was because the database isnt storing the login for future use in a temporary table, possibly?

KJ
 
I'm guessing the data type of UsersID is Number? If it is cbocourse1 is not returning a value and hence, the DLookup() function is returning Null.
 
Ok, that would make sense if the same code didnt work in the Main form, but it does. I basically copied the code and pasted it into the next forms OnCurrent event and modified some of the 'If' statements, so essentially it is the same code.

KJ
 
It's not about code, it's about data and what the value of the textbox is returning. So having the same code in two different forms is not a guarantee that it will work. Check the value of the combo box.
 
Ok, so userid is set as my Auto Number field in the table. The funny thing is when I run through the process to test it, as soon as I click the command button that opens the form with the offending code on it I get this run time error:

Run Time Error '2450':

Microsoft Access cannot find the referenced form 'frmLogin'.

So I checked the form name and matched it to the code in the database and they match...unsure as to why this run time error is popping up...I am lost here... :(

KJ
 
The form must be open before you call the code. Open as in running and not in Design View.
 
So is the oncurrent event the appropriate place for the code then? I have tested it live and that is when the errors pop up?
 
No it is called from the form I want access restricted to's oncurrent event.

It follows the following flow:

Login --> Main Menu (Access Restricted based on Security Level) code is in oncurrent event --> xyzform (certain views restricted based on same security determined at login) code is in oncurrent event.

I hope that helps describe the process flow.

KJ
 
Why is it in the On Current event? Shouldn't a one time verification be sufficient? E.g. putting it in the Load event of the form.
 
So, I put it on the Load event and I still get the same runtime error.

Do I need to leave the login form open or does that matter? Reason I ask is I thought I read somewhere that when a form closes (unloads) it refreshes and therefore the login information would be unloaded if you will. Thus causing the form to not recognize the security level.
 
Ding Ding Ding, it appearst hat I need to leave the login form open, and just hide it. It seems to now be working.
 
That was I mentioned in post #9. You can't get the value of a control if the form is closed.

Glad it's working.
 
Yeah I completely missed your implication there...I have been staring at this darn thing for a long time and my brain was melted. I appreciate the help! I will certainly be back again.

KJ
 

Users who are viewing this thread

Back
Top Bottom