MS access 2003 security

HI I have the below code in a function in a separate module and i am calling the function in the OnCUrrent event of the start up form . I want the same code to work for access versions of 2003 or above and it is working.  but the start up is not opening when the database is started  and i do not know why. So please help me guys.


Option Compare Database
Public Function mod_security()
    Dim UserName As String
    Dim curgroup As String
    Dim GroupNames(10) As String
    Dim ws As Workspace
    Dim usr As User
    'i will be used for dealing with the user groups ( counting the user groups, identify the group the current user belongs to)
    Dim i As Integer
    'j will be used for dealing with the toolbars( enabling and disabling them based on the user group)
    Dim j As Integer
    Dim filter As String
    Const Db_Text As Long = 10
    Const DB_Boolean As Long = 1
     
       'Disable the F 11 for both admin as well as users
       ChangeProperty "AllowSpecialKeys", DB_Boolean, False
       'Disalbe the Shift Key ( its another way to gain access to tables, forms, reports actually everything)
       ChangeProperty "AllowBypassKey", DB_Boolean, False
       DoCmd.RunCommand acCmdWindowHide

       'grabbing the user name of the user who logged on currently
       UserName = CurrentUser
       'DBEgine is the top level object in the hierarchy. you need to address DBEngine in order to access the users
       'in a group or connecting to a database. To get a clear picture highlight the below word "Workspaces" and hit f1
       'you will see a hierarchy of the objects and the order of access to the objects.
   Set ws = DBEngine.Workspaces(0)
   Set usr = ws.Users(UserName)

       'Put all groups user is in into an array
   For i = 0 To usr.Groups.Count - 1
       GroupNames(i) = usr.Groups(i).Name
   Next i

       'Loop through all the user groups
   For i = LBound(GroupNames) To UBound(GroupNames)
      Select Case GroupNames(i)
                  'If the user belongs to admin group, enable all the toolbars.
             Case "Admins"
                   For j = 1 To CommandBars.Count
                       CommandBars(j).Enabled = True
                       DoCmd.ShowToolbar "Menu Bar", acToolbarYes
                       DoCmd.ShowToolbar "Form Design", acToolbarYes
                       DoCmd.ShowToolbar "Formatting (Form/Report)", acToolbarYes
                       'if the MS access is 2007 or abbove , then enable the toolbar called "Ribbon"
                       If SysCmd(acSysCmdAccessVer) >= 12 Then
                          DoCmd.ShowToolbar "Ribbon", acToolbarYes
                       Else
                          Cancel = True
                       End If
                   Next j
                   Exit Function
                  'If the user belongs to user group, then disable all the toolbars
             Case "Users"
                   For j = 1 To CommandBars.Count
                       If InStr(CommandBars(j).Name, "Popup") = 0 Then
                          CommandBars(j).Enabled = False
                       End If
                       If SysCmd(acSysCmdAccessVer) >= 12 Then
                          DoCmd.ShowToolbar "Ribbon", acToolbarNo
                          DoCmd.ShowToolbar "Status Bar", acToolbarNo
                          DoCmd.LockNavigationPane True
                       Else
                          'If the access version is not 2007 or above, then " If loop" gets ended
                          Cancel = True
                       End If
                   Next j
      End Select
   Next i
End Function
vihaanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<< the OnCUrrent event of the start up form>>
  You should move it to the OnOpen or OnLoad event.  OnCurrent will only only fire if the form is bound and it will get fired a lot.  OnOpen/OnLoad will occur only once.
 JimD.
0
vihaanAuthor Commented:
Hi , well but now the toolbars and databasei window some of the stuff is not working when i logged in as user, it is supposed to hide the database window and disable the toolbars. but it is not doing that now.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
I would put a STOP at the top of your procedure and then execute the DB.
You can then step through your code line by line using F8 and detemine why it doesn't function as you expect.
While stepping through the code, you can also inspect values by hovering over them with the mouse, or can call up the debug window with Ctrl/G and do:
Debug.? GroupNames(i)
 For example.
JimD.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

vihaanAuthor Commented:
Hi when i tried to debug it , the function is not getting fired

And moreovr when i triedto achieve this through macro by naming it as autoexec. even then the startup is not getting opened. I do not know why
0
vihaanAuthor Commented:
Hi I do not know why but when i removed calling the function , there some code regarding the same basic stuff when i put a stop on the event and tried to debug it is not doing that. It is not taking me back to the event code. i do not know why.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Try calling the function directly from the Autoexec and forget about using a form for the moment.
The macro should be named Autoexec and for debugging purposes, only have a single line in it, which will be a RunCode action with nothing in the condition column.  Use mod_security for the argument.
JimD.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vihaanAuthor Commented:
Ya when i tried to do that thru macro. the code is working fine but as i said the startup is opening up . I do not know why
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<the code is working fine but as i said the startup is opening up >>
  Not sure what you mean by 'startup'; is that a form?  if so, I don't see where in your code your doing anything with the startup form property or opening a specific form.  
 What I would do is leave the startup form blank in tools/options and open the correct form at the end of your mod_security procedure.
JimD.
0
vihaanAuthor Commented:
Hi i am getting action failed when i tried to run the autoexec macro as soon as i opened the database. But ran it by double clicling it then it does not give me any error.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<Hi i am getting action failed when i tried to run the autoexec macro as soon as i opened the database. But ran it by double clicling it then it does not give me any error.>>
  You don't need to do anything to get it to run.  The Autoexec macro will be executed by Access as soon as you open the database.
JimD.
0
vihaanAuthor Commented:
exactly but i am getting action failed message but when ran it by going to database window and double clicking , it worked . That is very weird
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<exactly but i am getting action failed message but when ran it by going to database window and double clicking , it worked . That is very weird>>
  Yes, that is weird.  You have nothing else starting up?  You blanked out any startup form in tools/options?
  Do you get the error if you hold down the shift key to by-pass the autoexec?
JimD.
 
0
vihaanAuthor Commented:
No i did not got any error while using shift but do you know how to do that,.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.