Home All Groups Group Topic Archive Search About

Programatically load a form based on user login.

Author
19 Jul 2006 5:25 PM
Olu Solaru
Scenario.

I initially created a switchboard using Switchboard, but based on previous
advise, I created two forms instead ; Manufacturing and Regulatory.  These
forms are based on two groups that were created in Access security tool. 
(These forms contain controls to other objects -,,,Forms and Reports"

What I would like is that; Once a user in  the Manufacturing group logs into
the database, for example, the manufacturing form loads by default., and same
for the Regulatory group.

Another question, Once I move the orginial switchboard out of the Startup
option, Do I need to replace it with something else?

Author
19 Jul 2006 5:38 PM
Joan Wild
You likely only need one form, just hide buttons from the CurrentUser()
based on their group membership.

However if you want to proceed with your setup, you could have a hidden form
that opens on startup.  In its load event you can test which group the
current user is in and then open the appropriate form.

If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
  DoCmd.OpenForm "Name of Manufacturing Form"
Else
  DoCmd.OpenForm "Name of Regulatory Form"
End If

You do not have to have any form open on startup, however if you are using
the above, you'd have the hidden form open on startup

--
Joan Wild
Microsoft Access MVP

Olu Solaru wrote:
Show quoteHide quote
> Scenario.
>
> I initially created a switchboard using Switchboard, but based on
> previous advise, I created two forms instead ; Manufacturing and
> Regulatory.  These forms are based on two groups that were created in
> Access security tool. (These forms contain controls to other objects
> -,,,Forms and Reports"
>
> What I would like is that; Once a user in  the Manufacturing group
> logs into the database, for example, the manufacturing form loads by
> default., and same for the Regulatory group.
>
> Another question, Once I move the orginial switchboard out of the
> Startup option, Do I need to replace it with something else?
Author
19 Jul 2006 5:49 PM
Olu Solaru
I am not sure what you mean by Hidden form.  Once I open the database, I get
the default login prompt, based  on the fact that the database has been
secured.  How does the hidden form work in conjunction with the login prompt.?

Show quoteHide quote
"Joan Wild" wrote:

> You likely only need one form, just hide buttons from the CurrentUser()
> based on their group membership.
>
> However if you want to proceed with your setup, you could have a hidden form
> that opens on startup.  In its load event you can test which group the
> current user is in and then open the appropriate form.
>
> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>   DoCmd.OpenForm "Name of Manufacturing Form"
> Else
>   DoCmd.OpenForm "Name of Regulatory Form"
> End If
>
> You do not have to have any form open on startup, however if you are using
> the above, you'd have the hidden form open on startup
>
> --
> Joan Wild
> Microsoft Access MVP
>
> Olu Solaru wrote:
> > Scenario.
> >
> > I initially created a switchboard using Switchboard, but based on
> > previous advise, I created two forms instead ; Manufacturing and
> > Regulatory.  These forms are based on two groups that were created in
> > Access security tool. (These forms contain controls to other objects
> > -,,,Forms and Reports"
> >
> > What I would like is that; Once a user in  the Manufacturing group
> > logs into the database, for example, the manufacturing form loads by
> > default., and same for the Regulatory group.
> >
> > Another question, Once I move the orginial switchboard out of the
> > Startup option, Do I need to replace it with something else?
>
>
>
Author
19 Jul 2006 6:10 PM
Joan Wild
You would login via that login prompt.  After that, the startup form would
open.

By hidden, I mean put
Me.Visible = False
in the Open event of your startup form and in the Load event test the
current user.

I still think you could manage this with one form, hiding various buttons
based on the user's membership.


--
Joan Wild
Microsoft Access MVP

Olu Solaru wrote:
Show quoteHide quote
> I am not sure what you mean by Hidden form.  Once I open the
> database, I get the default login prompt, based  on the fact that the
> database has been secured.  How does the hidden form work in
> conjunction with the login prompt.?
>
> "Joan Wild" wrote:
>
>> You likely only need one form, just hide buttons from the
>> CurrentUser() based on their group membership.
>>
>> However if you want to proceed with your setup, you could have a
>> hidden form that opens on startup.  In its load event you can test
>> which group the current user is in and then open the appropriate
>> form.
>>
>> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>>   DoCmd.OpenForm "Name of Manufacturing Form"
>> Else
>>   DoCmd.OpenForm "Name of Regulatory Form"
>> End If
>>
>> You do not have to have any form open on startup, however if you are
>> using the above, you'd have the hidden form open on startup
>>
>> --
>> Joan Wild
>> Microsoft Access MVP
>>
>> Olu Solaru wrote:
>>> Scenario.
>>>
>>> I initially created a switchboard using Switchboard, but based on
>>> previous advise, I created two forms instead ; Manufacturing and
>>> Regulatory.  These forms are based on two groups that were created
>>> in Access security tool. (These forms contain controls to other
>>> objects -,,,Forms and Reports"
>>>
>>> What I would like is that; Once a user in  the Manufacturing group
>>> logs into the database, for example, the manufacturing form loads by
>>> default., and same for the Regulatory group.
>>>
>>> Another question, Once I move the orginial switchboard out of the
>>> Startup option, Do I need to replace it with something else?
Author
19 Jul 2006 7:06 PM
Olu Solaru
I have decided to follow your advice and use one form.  I just created a new
form with all the command buttons.  

One Question.  Where Do I declare the Function IF Faq_IsUserInGroup, in the
Open Event or the Load Event.   Am I to Assume that the Open Event of the
form will only contain the (Me.Visible = False ) line.?

Show quoteHide quote
"Joan Wild" wrote:

> You would login via that login prompt.  After that, the startup form would
> open.
>
> By hidden, I mean put
> Me.Visible = False
> in the Open event of your startup form and in the Load event test the
> current user.
>
> I still think you could manage this with one form, hiding various buttons
> based on the user's membership.
>
>
> --
> Joan Wild
> Microsoft Access MVP
>
> Olu Solaru wrote:
> > I am not sure what you mean by Hidden form.  Once I open the
> > database, I get the default login prompt, based  on the fact that the
> > database has been secured.  How does the hidden form work in
> > conjunction with the login prompt.?
> >
> > "Joan Wild" wrote:
> >
> >> You likely only need one form, just hide buttons from the
> >> CurrentUser() based on their group membership.
> >>
> >> However if you want to proceed with your setup, you could have a
> >> hidden form that opens on startup.  In its load event you can test
> >> which group the current user is in and then open the appropriate
> >> form.
> >>
> >> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
> >>   DoCmd.OpenForm "Name of Manufacturing Form"
> >> Else
> >>   DoCmd.OpenForm "Name of Regulatory Form"
> >> End If
> >>
> >> You do not have to have any form open on startup, however if you are
> >> using the above, you'd have the hidden form open on startup
> >>
> >> --
> >> Joan Wild
> >> Microsoft Access MVP
> >>
> >> Olu Solaru wrote:
> >>> Scenario.
> >>>
> >>> I initially created a switchboard using Switchboard, but based on
> >>> previous advise, I created two forms instead ; Manufacturing and
> >>> Regulatory.  These forms are based on two groups that were created
> >>> in Access security tool. (These forms contain controls to other
> >>> objects -,,,Forms and Reports"
> >>>
> >>> What I would like is that; Once a user in  the Manufacturing group
> >>> logs into the database, for example, the manufacturing form loads by
> >>> default., and same for the Regulatory group.
> >>>
> >>> Another question, Once I move the orginial switchboard out of the
> >>> Startup option, Do I need to replace it with something else?
>
>
>
Author
19 Jul 2006 7:57 PM
Joan Wild
The security FAQ:
http://support.microsoft.com/?id=207793
has the function FAQ_IsUserInGroup.

Just copy the function and paste it in a module.  Save the module giving it
a name different that the function.

Since you are going with one form, you can go back to my original suggestion
of putting it in the open event of the form.

If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
  Me!cmdSomething.Visible = True
  Me!cmdWhatever.Visible = True
etc
Else
    Me!cmdSomething.visible = false
  Me!cmdWhatever.Visible = False
etc
End If

Substitue cmdSomething and cmdWhatever with the actual names of your command
buttons.

--
Joan Wild
Microsoft Access MVP

Olu Solaru wrote:
Show quoteHide quote
> I have decided to follow your advice and use one form.  I just
> created a new form with all the command buttons.
>
> One Question.  Where Do I declare the Function IF Faq_IsUserInGroup,
> in the Open Event or the Load Event.   Am I to Assume that the Open
> Event of the form will only contain the (Me.Visible = False ) line.?
>
> "Joan Wild" wrote:
>
>> You would login via that login prompt.  After that, the startup form
>> would open.
>>
>> By hidden, I mean put
>> Me.Visible = False
>> in the Open event of your startup form and in the Load event test the
>> current user.
>>
>> I still think you could manage this with one form, hiding various
>> buttons based on the user's membership.
>>
>>
>> --
>> Joan Wild
>> Microsoft Access MVP
>>
>> Olu Solaru wrote:
>>> I am not sure what you mean by Hidden form.  Once I open the
>>> database, I get the default login prompt, based  on the fact that
>>> the database has been secured.  How does the hidden form work in
>>> conjunction with the login prompt.?
>>>
>>> "Joan Wild" wrote:
>>>
>>>> You likely only need one form, just hide buttons from the
>>>> CurrentUser() based on their group membership.
>>>>
>>>> However if you want to proceed with your setup, you could have a
>>>> hidden form that opens on startup.  In its load event you can test
>>>> which group the current user is in and then open the appropriate
>>>> form.
>>>>
>>>> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>>>>   DoCmd.OpenForm "Name of Manufacturing Form"
>>>> Else
>>>>   DoCmd.OpenForm "Name of Regulatory Form"
>>>> End If
>>>>
>>>> You do not have to have any form open on startup, however if you
>>>> are using the above, you'd have the hidden form open on startup
>>>>
>>>> --
>>>> Joan Wild
>>>> Microsoft Access MVP
>>>>
>>>> Olu Solaru wrote:
>>>>> Scenario.
>>>>>
>>>>> I initially created a switchboard using Switchboard, but based on
>>>>> previous advise, I created two forms instead ; Manufacturing and
>>>>> Regulatory.  These forms are based on two groups that were created
>>>>> in Access security tool. (These forms contain controls to other
>>>>> objects -,,,Forms and Reports"
>>>>>
>>>>> What I would like is that; Once a user in  the Manufacturing group
>>>>> logs into the database, for example, the manufacturing form loads
>>>>> by default., and same for the Regulatory group.
>>>>>
>>>>> Another question, Once I move the orginial switchboard out of the
>>>>> Startup option, Do I need to replace it with something else?
Author
19 Jul 2006 8:09 PM
Olu Solaru
Sorry for sounding stupid.
But am I still creating the module or just copying the following code in the
Open Event of the form?. -

If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
  Me!cmdSomething.Visible = True
  Me!cmdWhatever.Visible = True

Else    
Me!cmdSomething.visible = false
   Me!cmdWhatever.Visible = False
etc
End If

Because When I tried it that way it says something about the Function not
being declared, So I am assuming that I have to do something in addition to
adding the code to the Open Event of the form.

Show quoteHide quote
"Joan Wild" wrote:

> The security FAQ:
http://support.microsoft.com/?id=207793
> has the function FAQ_IsUserInGroup.
>
> Just copy the function and paste it in a module.  Save the module giving it
> a name different that the function.
>
> Since you are going with one form, you can go back to my original suggestion
> of putting it in the open event of the form.
>
> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>   Me!cmdSomething.Visible = True
>   Me!cmdWhatever.Visible = True
> etc
> Else
>     Me!cmdSomething.visible = false
>   Me!cmdWhatever.Visible = False
> etc
> End If
>
> Substitue cmdSomething and cmdWhatever with the actual names of your command
> buttons.
>
> --
> Joan Wild
> Microsoft Access MVP
>
> Olu Solaru wrote:
> > I have decided to follow your advice and use one form.  I just
> > created a new form with all the command buttons.
> >
> > One Question.  Where Do I declare the Function IF Faq_IsUserInGroup,
> > in the Open Event or the Load Event.   Am I to Assume that the Open
> > Event of the form will only contain the (Me.Visible = False ) line.?
> >
> > "Joan Wild" wrote:
> >
> >> You would login via that login prompt.  After that, the startup form
> >> would open.
> >>
> >> By hidden, I mean put
> >> Me.Visible = False
> >> in the Open event of your startup form and in the Load event test the
> >> current user.
> >>
> >> I still think you could manage this with one form, hiding various
> >> buttons based on the user's membership.
> >>
> >>
> >> --
> >> Joan Wild
> >> Microsoft Access MVP
> >>
> >> Olu Solaru wrote:
> >>> I am not sure what you mean by Hidden form.  Once I open the
> >>> database, I get the default login prompt, based  on the fact that
> >>> the database has been secured.  How does the hidden form work in
> >>> conjunction with the login prompt.?
> >>>
> >>> "Joan Wild" wrote:
> >>>
> >>>> You likely only need one form, just hide buttons from the
> >>>> CurrentUser() based on their group membership.
> >>>>
> >>>> However if you want to proceed with your setup, you could have a
> >>>> hidden form that opens on startup.  In its load event you can test
> >>>> which group the current user is in and then open the appropriate
> >>>> form.
> >>>>
> >>>> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
> >>>>   DoCmd.OpenForm "Name of Manufacturing Form"
> >>>> Else
> >>>>   DoCmd.OpenForm "Name of Regulatory Form"
> >>>> End If
> >>>>
> >>>> You do not have to have any form open on startup, however if you
> >>>> are using the above, you'd have the hidden form open on startup
> >>>>
> >>>> --
> >>>> Joan Wild
> >>>> Microsoft Access MVP
> >>>>
> >>>> Olu Solaru wrote:
> >>>>> Scenario.
> >>>>>
> >>>>> I initially created a switchboard using Switchboard, but based on
> >>>>> previous advise, I created two forms instead ; Manufacturing and
> >>>>> Regulatory.  These forms are based on two groups that were created
> >>>>> in Access security tool. (These forms contain controls to other
> >>>>> objects -,,,Forms and Reports"
> >>>>>
> >>>>> What I would like is that; Once a user in  the Manufacturing group
> >>>>> logs into the database, for example, the manufacturing form loads
> >>>>> by default., and same for the Regulatory group.
> >>>>>
> >>>>> Another question, Once I move the orginial switchboard out of the
> >>>>> Startup option, Do I need to replace it with something else?
>
>
>
Author
19 Jul 2006 10:11 PM
Joan Wild
If you have an existing module, open it and paste the Function in it (if you
don't have a module then create a new one on the Modules tab).

Paste the function from the security FAQ (it's in section 22; just copy and
paste the code from 'Determine if a User is in a given Group:)

Function faq_IsUserInGroup (strGroup As String, strUser as String) As
Integer
.....
....
...

End Function

Now open your form in design view and bring up the properties sheet.  In the
On Open property, click the dropdown and choose Event Procedure.  Then click
on the build button(...) and put
If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True then
Me!cmdSomething.Visible = True
Else
Me!cmdSomething.Visible = False
End If

Does that help?


--
Joan Wild
Microsoft Access MVP

Olu Solaru wrote:
Show quoteHide quote
> Sorry for sounding stupid.
> But am I still creating the module or just copying the following code
> in the Open Event of the form?. -
>
> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>  Me!cmdSomething.Visible = True
>  Me!cmdWhatever.Visible = True
>
> Else
> Me!cmdSomething.visible = false
>   Me!cmdWhatever.Visible = False
> etc
> End If
>
> Because When I tried it that way it says something about the Function
> not being declared, So I am assuming that I have to do something in
> addition to adding the code to the Open Event of the form.
>
> "Joan Wild" wrote:
>
>> The security FAQ:
>>  http://support.microsoft.com/?id=207793
>> has the function FAQ_IsUserInGroup.
>>
>> Just copy the function and paste it in a module.  Save the module
>> giving it a name different that the function.
>>
>> Since you are going with one form, you can go back to my original
>> suggestion of putting it in the open event of the form.
>>
>> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>>   Me!cmdSomething.Visible = True
>>   Me!cmdWhatever.Visible = True
>> etc
>> Else
>>     Me!cmdSomething.visible = false
>>   Me!cmdWhatever.Visible = False
>> etc
>> End If
>>
>> Substitue cmdSomething and cmdWhatever with the actual names of your
>> command buttons.
>>
>> --
>> Joan Wild
>> Microsoft Access MVP
>>
>> Olu Solaru wrote:
>>> I have decided to follow your advice and use one form.  I just
>>> created a new form with all the command buttons.
>>>
>>> One Question.  Where Do I declare the Function IF Faq_IsUserInGroup,
>>> in the Open Event or the Load Event.   Am I to Assume that the Open
>>> Event of the form will only contain the (Me.Visible = False ) line.?
>>>
>>> "Joan Wild" wrote:
>>>
>>>> You would login via that login prompt.  After that, the startup
>>>> form would open.
>>>>
>>>> By hidden, I mean put
>>>> Me.Visible = False
>>>> in the Open event of your startup form and in the Load event test
>>>> the current user.
>>>>
>>>> I still think you could manage this with one form, hiding various
>>>> buttons based on the user's membership.
>>>>
>>>>
>>>> --
>>>> Joan Wild
>>>> Microsoft Access MVP
>>>>
>>>> Olu Solaru wrote:
>>>>> I am not sure what you mean by Hidden form.  Once I open the
>>>>> database, I get the default login prompt, based  on the fact that
>>>>> the database has been secured.  How does the hidden form work in
>>>>> conjunction with the login prompt.?
>>>>>
>>>>> "Joan Wild" wrote:
>>>>>
>>>>>> You likely only need one form, just hide buttons from the
>>>>>> CurrentUser() based on their group membership.
>>>>>>
>>>>>> However if you want to proceed with your setup, you could have a
>>>>>> hidden form that opens on startup.  In its load event you can
>>>>>> test which group the current user is in and then open the
>>>>>> appropriate form.
>>>>>>
>>>>>> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>>>>>>   DoCmd.OpenForm "Name of Manufacturing Form"
>>>>>> Else
>>>>>>   DoCmd.OpenForm "Name of Regulatory Form"
>>>>>> End If
>>>>>>
>>>>>> You do not have to have any form open on startup, however if you
>>>>>> are using the above, you'd have the hidden form open on startup
>>>>>>
>>>>>> --
>>>>>> Joan Wild
>>>>>> Microsoft Access MVP
>>>>>>
>>>>>> Olu Solaru wrote:
>>>>>>> Scenario.
>>>>>>>
>>>>>>> I initially created a switchboard using Switchboard, but based
>>>>>>> on previous advise, I created two forms instead ; Manufacturing
>>>>>>> and Regulatory.  These forms are based on two groups that were
>>>>>>> created in Access security tool. (These forms contain controls
>>>>>>> to other objects -,,,Forms and Reports"
>>>>>>>
>>>>>>> What I would like is that; Once a user in  the Manufacturing
>>>>>>> group logs into the database, for example, the manufacturing
>>>>>>> form loads by default., and same for the Regulatory group.
>>>>>>>
>>>>>>> Another question, Once I move the orginial switchboard out of
>>>>>>> the Startup option, Do I need to replace it with something else?
Author
19 Jul 2006 6:05 PM
Olu Solaru
Do I have to declare faq_IsUserInGroup as a Function?

Show quoteHide quote
"Joan Wild" wrote:

> You likely only need one form, just hide buttons from the CurrentUser()
> based on their group membership.
>
> However if you want to proceed with your setup, you could have a hidden form
> that opens on startup.  In its load event you can test which group the
> current user is in and then open the appropriate form.
>
> If faq_IsUserInGroup("Manufacturing",CurrentUser()) = True Then
>   DoCmd.OpenForm "Name of Manufacturing Form"
> Else
>   DoCmd.OpenForm "Name of Regulatory Form"
> End If
>
> You do not have to have any form open on startup, however if you are using
> the above, you'd have the hidden form open on startup
>
> --
> Joan Wild
> Microsoft Access MVP
>
> Olu Solaru wrote:
> > Scenario.
> >
> > I initially created a switchboard using Switchboard, but based on
> > previous advise, I created two forms instead ; Manufacturing and
> > Regulatory.  These forms are based on two groups that were created in
> > Access security tool. (These forms contain controls to other objects
> > -,,,Forms and Reports"
> >
> > What I would like is that; Once a user in  the Manufacturing group
> > logs into the database, for example, the manufacturing form loads by
> > default., and same for the Regulatory group.
> >
> > Another question, Once I move the orginial switchboard out of the
> > Startup option, Do I need to replace it with something else?
>
>
>