Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 29th, 2004, 02:26 PM
krulin23 krulin23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Chicago
Posts: 10 krulin23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!!

Reply With Quote
  #2  
Old December 30th, 2004, 08:48 AM
MrBullwinkle MrBullwinkle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Wild and Wonderful, West Virginia
Posts: 27 MrBullwinkle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MrBullwinkle Send a message via AIM to MrBullwinkle Send a message via MSN to MrBullwinkle Send a message via Yahoo to MrBullwinkle
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.

Reply With Quote
  #3  
Old January 2nd, 2005, 03:50 PM
ejkujan ejkujan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 6 ejkujan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old January 3rd, 2005, 10:20 AM
gfulton gfulton is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Atlanta, GA
Posts: 42 gfulton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 53 sec
Reputation Power: 5
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!

Reply With Quote
  #5  
Old January 3rd, 2005, 01:55 PM
MrBullwinkle MrBullwinkle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Wild and Wonderful, West Virginia
Posts: 27 MrBullwinkle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MrBullwinkle Send a message via AIM to MrBullwinkle Send a message via MSN to MrBullwinkle Send a message via Yahoo to MrBullwinkle
Lightbulb

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.

Reply With Quote
  #6  
Old January 3rd, 2005, 06:52 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
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

Reply With Quote
  #7  
Old January 4th, 2005, 09:23 AM
MrBullwinkle MrBullwinkle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Wild and Wonderful, West Virginia
Posts: 27 MrBullwinkle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MrBullwinkle Send a message via AIM to MrBullwinkle Send a message via MSN to MrBullwinkle Send a message via Yahoo to MrBullwinkle
What is included in "Run time procedures"? Just what we want to happen, or certain Access events?

Reply With Quote
  #8  
Old January 4th, 2005, 01:10 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
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

Reply With Quote
  #9  
Old January 4th, 2005, 01:50 PM
krulin23 krulin23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Chicago
Posts: 10 krulin23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Thanks for all the help...

Quote:
Originally Posted by lwells
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


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

Reply With Quote
  #10  
Old January 4th, 2005, 01:51 PM
krulin23 krulin23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Chicago
Posts: 10 krulin23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by MrBullwinkle
What is included in "Run time procedures"? Just what we want to happen, or certain Access events?


Basically just the different forms opening and each form has a different layout..

Reply With Quote
  #11  
Old January 4th, 2005, 01:56 PM
krulin23 krulin23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Chicago
Posts: 10 krulin23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by gfulton
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!

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!

Reply With Quote
  #12  
Old January 4th, 2005, 04:47 PM
gfulton gfulton is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Atlanta, GA
Posts: 42 gfulton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 53 sec
Reputation Power: 5
Quote:
Originally Posted by krulin23
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!

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. :-)

Reply With Quote
  #13  
Old January 4th, 2005, 11:06 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
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

Reply With Quote
  #14  
Old January 6th, 2005, 11:25 AM
krulin23 krulin23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Chicago
Posts: 10 krulin23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool

Quote:
Originally Posted by gfulton
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. :-)
.


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..

Reply With Quote
  #15  
Old January 6th, 2005, 11:27 AM
krulin23 krulin23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Chicago
Posts: 10 krulin23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Quote:
Originally Posted by lwells
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

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!!

Reply With Quote