|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to open different forms
Help, I want to know how to open different forms depending on your access
rights or level.example. Table Users with fields: Username...Password.....Userlevel If i am the Administrator I should be able to login and then a Form name Switchboard appears, if i am just a User on the Userlevel then i want Form name Switchboard1 to appear PLEASE HELP, THANKS!! ![]() |
|
#2
|
|||
|
|||
|
I thought there was a way to run a macro/code on startup, but I've not found it. Another way would be to make one of the switchboards the opening form. For that form in the On Open event, run a function (returns nothing, but cannot be a sub) that checks for the user level. If the userlever is the one that corresponds to this form, then you're set, if not, open the other form and close this one.
|
|
#3
|
|||
|
|||
|
Use VBA to make the decision on which to open. If the tasks are basically the same with a few differnt it is probly better to use the same form but use VBA to make changes to the buttons by enabling/disabling, changing text, or turning visibility on/off. This keeps coding down because your combining code for both types of users and not duplicating it on two forms. The changes can be made probly in one sub when the form is opened and you wouldn't have to worry about it after that.
|
|
#4
|
|||
|
|||
|
This was the best answer I was given. It was posted by LWells earlier in this board...
There are several ways to go about restricting objects within the database. You can use the User-Level Security Wizard as one method and just follow the wizard prompts to grant permissions to the specific database objects, or you can write some VBA code that will open a specific form with an autoexec macro based on the CurrentUser. Example If CurrentUser = "Admin" Then DoCmd.OpenForm "Switchboard" Else DoCmd.OpenForm "Name of Form" End If ..At the time I could not make an autoexec macro either, so I made a form called LOGIN. This was the form that the database opened up to, and it simply said "You are logged in as (name)" ...I used a text box with the control source=currentuser(). This auto populated the field with whoever was logged in at the time. Then I placed a command button on the form that said "Continue" and placed the above code in the "OnClick" command. Worked like a charm. In fact, I have not bothered to change it. Good luck! |
|
#5
|
|||
|
|||
|
I found a "cheating" way to run a macro on startup. Create a basically blank form, and in the On Load event put your macro. Then make that form the startup. If in your code you hide that "blank" form and be sure to open something else, the world may never know.
|
|
#6
|
|||
|
|||
|
To create an Autoexec macro, all you have to do is create your macro with all the run time procedures and then give it the name Autoexec. This macro will then run during start up first and perform any procedures or functions called by the macro. The other suggestions offered will work just as well.
lwells |
|
#7
|
|||
|
|||
|
What is included in "Run time procedures"? Just what we want to happen, or certain Access events?
|
|
#8
|
|||
|
|||
|
An example would be if you wanted to have the user enter his name before opening a database as an example, placing the following code into a module to determine which form to open:
Function Login() Dim strInput As String strInput = InputBox("Please Enter Your Name") If strInput = "John Doe" Then DoCmd.OpenForm "Form1" Else DoCmd.OpenForm "Form2" End If End Function Then create a macro to run this code and give it the name Autoexec. When the application is started, this input box will display asking for the user name. If in the above example the user enters "John Doe", then Form1 will open, otherwise Form2 will open if any other name is typed in. In effect you can do whatever you want to do in the way of procedures or events in vba code and make a macro to run the code on start up. Was this your question? lwells |
|
#9
|
|||
|
|||
|
Quote:
Hello, This is the VB code i used to do, so how would i incorporate the above code to check for UseLevel: Admin and User...for Admin open switchboard and for User open switchboard1.. and then open the different forms accordingly? Dim GetData As ADODB.Recordset Set GetData = New ADODB.Recordset If IsNull(Me.UserTxt) Then MsgBox "Please enter a valid user name.", vbExclamation, "Error" Me.UserTxt.SetFocus Exit Sub ElseIf IsNull(Me.PassTxt) Then MsgBox "Please enter a valid password.", vbExclamation, "Error" Me.PassTxt.SetFocus Exit Sub End If GetData.Open "SELECT * FROM tblUser WHERE(UserName = """ & Me.UserTxt & """ AND Pass = """ & Me.PassTxt & """)", _ CurrentProject.Connection, adOpenKeyset, adLockOptimistic If GetData.EOF Then MsgBox "Invalid user name or password. Please try again.", vbExclamation, "Error" Me.UserTxt.SetFocus Exit Sub End If MsgBox "Login Successful.", vbInformation, "Confirm!" Dim stDocName As String DoCmd.Close stDocName = "Switchboard" DoCmd.OpenForm stDocName DoCmd.Maximize Exit Sub |
|
#10
|
|||
|
|||
|
Quote:
Basically just the different forms opening and each form has a different layout.. |
|
#11
|
|||
|
|||
|
Quote:
The problem with using the Wizard is that once you put it on the network you will always have to use or anyone in that network must enter in a password to access any future Access Database program even if they are not the intended users, please let me know if i am understanding this correctly, THanks! |
|
#12
|
|||
|
|||
|
Quote:
I have not run into that problem. I created the secure database on a shared drive, the end-user has only read/write access to the folder, the database is secured with the wizzard, and then I create a shortcut to the secured database on the desktop of the end user. When they use the shortcut, they are prompted for their password, when they access the main company database (open to all employees) they are not prompted for anything because that database in not associated with the secure file of the secure database. OK...this makes sense to me...I hope you understand my rambling. :-) |
|
#13
|
|||
|
|||
|
Hi Krulin23
Guess I need a little clarification from you before I can be more specific for you. From your post...are you using a table for your determination of who is logging into the database? It looks like you might have a login form you created that comes up and the user types in his name and password...is this correct. Secondly, have you set up user and groups permissions using the Database Security Wizard? If so you have created a workgroup information file that will contain all the permissions etc for each object or group. Generally it is better to set permissions to groups rather than individuals. That way a new user can be assigned to a group and will inherent those permissions. You can then use this information to determine which forms (or Switchboards) you want to open depending on who the current user is. Either of the two methods above can be placed into a macro for start up. The first method you showed requires a prompt from the user to enter a name and password on a form. Then using vba to check against a table to determine if the user can continue to open the database or go to a specific form. Which is pretty much what you have already accomplished from what I can tell. The second method would use the current user login information based on which group the user was assigned to open a specific form or in your case switchboard. This method the user still enters his name and password to login, the only difference being that a table doesn't have to be maintained (and a lot more secure than the first method). A new user is added through the security menus and assigned to a group by the admin, then when the new user logs in, the correct switchboard or form will open automatically based on what group the user was assigned. A generic sample code for something like that would be: Function GetCorrectForm() Dim grp As Group Dim usr As User For Each usr In DBEngine(0).Users For Each grp In usr.Groups If grp.Name = "SpecificGroupName" Then If CurrentUser = usr.Name Then DoCmd.OpenForm "UserSwitchboard" Exit Function ElseIf CurrentUser = "Admin" Then DoCmd.OpenForm "AdminSwitchboard" Exit Function End If End If Next Next End Function The code is very generic, but the methods shown can be used to determine what to do based on who is logged in if you have set up the groups and user permissions correctly. It also needs to have error handling added. If you need additional help or if need something different post back. lwells |
|
#14
|
|||
|
|||
|
Quote:
Alright got it to work, another question, so whenever you go back to the database and create or add another user you go through the same process but on that persons computer and then it will prompt to automatically create a shortcut right? Thanks for all the help.. |
|
#15
|
|||
|
|||
|
Quote:
Again, Thanks for all the help, i will try this also and let you know of any changes. How do you restrict the right click to view form for design view?? Thanks!! |