|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help with an IF statement for the groupsHello
I have 2 groups: Admins, EnterData I want to display some objects in my forms when the EnterData group users are logon and display all the objects when the Admins are logon on. My question: Where do I put the code, is it under: Form Load, Form Open, or where? What is the actual code that I need to write in order to implement what I want Thanks erick-flores wrote:
> Hello You don't want to give users access to the database window at all. You > > I have 2 groups: Admins, EnterData > > I want to display some objects in my forms when the EnterData group > users are logon and display all the objects when the Admins are logon > on. should create a 'menu' type form that allows users to open the various forms/reports that they need to use. This form would just have command buttons on it to open the various forms, etc. You can hide buttons depending on the group the user is a member of. There is code in the security FAQ you can use to determine if a user is a member of a group. In the open event of this menu form you'd use... If faq_IsUserInGroup("EnterData",CurrentUser) then Me.cmdWhatever.Visible = False Me.cmdSomething.Visible = False Else Me.cmdWhatever.Visible = True Me.cmdSomething.Visible = True End If Create custom menus/toolbars for use throughout your application. Use the features in Tools, Startup to set the startup form (your menu form) set your default menu (the custom one you made) disable all the checkboxes about allowing built in menus, toolbars, changes etc. hide the db window (ensure the custom menu you create does not include the Windows, Unhide item) uncheck the allow special keys (this will disable the F11 key, among others) If you need to bypass these startup features, you can hold the shift key down while you open the db. If you feel that your users may use this to bypass your settings, you can disable the shift key bypass - there's an example in help for doing this(look for AllowBypassKey) or at http://www.mvps.org/access/modules/mdl0011.htm and http://www.mvps.org/access/general/gen0040.htm You can also create a MDE from your database, which will prevent changes to forms, reports and modules (If you do this, be certain to keep your original mdb in case you need to make changes). -- Joan Wild Microsoft Access MVP OK, I tried the IF statement, but its giving the fol error:
Compile Error: Sub or Function not defined Here is my code behind the Open event: Private Sub Form_Open(Cancel As Integer) If faq_IsUserInGroup("EnterData", CurrentUser) Then Me.Label44.Visible = False 'Me.cmdSomething.Visible = False Else Me.Label44.Visible = True 'Me.cmdSomething.Visible = True End If it higlights Private Sub_Open (Cancel As Integer) in yellow and it highlights faq_IsUserInGroup in blue I did read that file SECFAQ.doc for this manner got that code you gave me and test it, but got the same results. Do you know whats going on? I am doing something wrong? Try doing the IF stat. for the recourdsource and got the same problem
with the faq_IsUserInGroup function. So I guess the problem is the function...maybe I am doing something wrong? Where did you put the function? You should open a new module (on the
modules tab), paste the faq_IsUserInGroup function and save the module (give it a name different than the name of the function). -- Show quoteHide quoteJoan Wild Microsoft Access MVP erick-flores wrote: > Try doing the IF stat. for the recourdsource and got the same problem > with the faq_IsUserInGroup function. So I guess the problem is the > function...maybe I am doing something wrong? Joan Wild wrote:
> Where did you put the function? You should open a new module (on the Thank you very much, its working now...I created the module and the> modules tab), paste the faq_IsUserInGroup function and save the module (give > it a name different than the name of the function). > function is working. But I am having problems with the Me.RecordSource part under the faq_IsUserInGroup function. Here is what I have done, this code is behind the form that opens when the .mdb is open: Private Sub Form_BeforeUpdate(Cancel As Integer) If faq_IsUserInGroup("Admins", CurrentUser) Then Me.RecordSource = "SELECT * FROM Employees" Else [UsernameHold] = CurrentUser Me.RecordSource = "SELECT * FROM Employees WHERE [UsernameHold] = " & CurrentUser() End If End Sub I put [Event Procedure] under the Data for the Record Source for the Form...I dont know if this is the right way of doing it. Its giving me the error: "The record source '[Event Procedure]' specified on this form or report does not exist." I can understand the error but I dont know how to fix it so it can look at the IF statement Any ideas??? Thank you again, I swear this is the last question...after this one hopefully I will be done :-) erick-flores wrote:
Show quoteHide quote > Joan Wild wrote: No don't do that; change it back to Employees.>> Where did you put the function? You should open a new module (on the >> modules tab), paste the faq_IsUserInGroup function and save the >> module (give it a name different than the name of the function). >> > Thank you very much, its working now...I created the module and the > function is working. > But I am having problems with the Me.RecordSource part under the > faq_IsUserInGroup function. > Here is what I have done, this code is behind the form that opens when > the .mdb is open: > > Private Sub Form_BeforeUpdate(Cancel As Integer) > If faq_IsUserInGroup("Admins", CurrentUser) Then > Me.RecordSource = "SELECT * FROM Employees" > Else > [UsernameHold] = CurrentUser > Me.RecordSource = "SELECT * FROM Employees WHERE [UsernameHold] = " > & CurrentUser() > End If > End Sub > > I put [Event Procedure] under the Data for the Record Source for the > Form...I dont know if this is the right way of doing it. Its giving me > the error: The code above should not be on the main form when the mdb opens. It should be on the form (and every form) where users view/edit data. This was just one example for the form where users are viewing the Employees data. If you have other forms you need to do the same on them, but change the SQL statement to reflect the recordsource for each form. Open the form in design view. In the properties for the form, select [Event Procedure] in the dropdown beside the Before Update event property. Then click on the build button (...) Between the two lines presented put If faq_IsUserInGroup.... etc End If. -- Joan Wild Microsoft Access MVP I got it...I guess my problem is that I am always trying to complicate
things too much when they can be done in an easier way Thank you for your help, I will now present the final project to my boss and see if she likes it :-) |
|||||||||||||||||||||||