How to disable and enable the secondary menu bar if the user is false

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aaitaman Tamang
    New Member
    • Jul 2011
    • 22

    How to disable and enable the secondary menu bar if the user is false

    All,

    I have db which contained user login system which mean i have form that opens when i open db. Also i have created my own menu bar. What i am looking for is how to disable menu bar that i have created if the the user logged invalid and enable if the user valid

    in other words, i don't want user to open any other forms from the menu bar if the users click on the menu bar items without login

    Any prompt help appreciated
    Thanks,
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Here is the Semi-Suedo Code (just made that up) given a Custom Menu Bar named Custom Menu:
    Code:
    Dim blnValidLogin As Boolean
    
    'blnValidLogin will return either True or False
    'blnValidLogin = (Username & Password are an exact Match)
    
    'Show/do not Show based on Current Value of blnValidLogin
    If blnValidLogin Then
      DoCmd.ShowToolbar "Custom Menu", acToolbarYes
    Else
      DoCmd.ShowToolbar "Custom Menu", acToolbarNo
    End If
    Code:
    Dim blnValidLogin As Boolean
      
    'blnValidLogin will return either True or False
    'blnValidLogin = (Username & Password are an exact Match)
    
    blnValidLogin = False
      
    Application.CommandBars("Relationship").Enabled = blnValidLogin
    Last edited by ADezii; Jul 17 '11, 02:13 PM. Reason: Provide another, alternative approach using CommandBars

    Comment

    • Aaitaman Tamang
      New Member
      • Jul 2011
      • 22

      #3
      Dezii,
      Thanks for your help. It did not work. I think something wrong with me as i am new on VBA. As i run that code i got runtime error 2094 (Can't find the tool barbar "Custom Menu")
      Dezi, may be i could not explained enought of need.
      Here is another example of my needs:
      1) I have form called user login where users need to login first with their valid user name & password.
      2)I have Created own menu bar where user can see the different options with drop down list.
      3)I have removed the default and added my menu bar as a start up.

      Now i want VBA code to disable & enable of menu bar if the user use invalid user name and password

      If user is valid then Menu bar enable
      else
      Menu bar disable

      I know, you can help me out.

      Thanks,

      Comment

      • Adam Tippelt
        New Member
        • Nov 2010
        • 137

        #4
        I imagine you got that error because ADezii was using 'Custom Menu' as the variable name which you should have replaced with the name of your own menu. As he said it iss semi-suedo it wouldn't just run as is.

        Is your login form separate to the 'main menu' form, or are they the same form with the menu hidden until valid login?

        I have a setup whereby I use a login form which then closes and opens the main menu. I use the following code for login validation:

        Code:
        Private Sub Login_Click()
        
        'Check if the username field is empty.
        If IsNull(Me.Username) Or Me.Username = "" Then
            MsgBox "You must enter a Username.", vbOKOnly
            Me.Username.SetFocus
            Exit Sub
        End If
        
        'Check if the password field is empty.
        If IsNull(Me.Password) Or Me.Password = "" Then
            MsgBox "You must enter a Password.", vbOKOnly
            Me.Password.SetFocus
            Exit Sub
        End If
        
        'Confirm if the password is correct for the username entered.
        If Me.Password = DLookup("Password", "tblUsers", "[UserName]= '" & Replace(Me.Username, "'", "''") & "'") Then
            DoCmd.Close acForm, "Login Page"
            DoCmd.OpenForm "Main Menu"
        Else
            MsgBox "Incorrect username or password. Please try again.", vbOKOnly + vbCritical, "Access Denied."
            Me.Username.SetFocus
        End If
        
        End Sub
        This works on the assumption that you have a table which stores your User details.
        Note that this code includes the variable names that I use in my own code - these are the things which you should replace with the names of variables in YOUR code:

        Login_Click = Login is the name of the button clicked to initiate this procedure. (The _Click suffix is not part of the name, it's just to make it clearer what I'm referring to)
        (Likewise, the Me. prefix is not part of the name, it's just to make it clearer what I'm referring to)
        Me.Username = Username field on the login form.
        Me.Password = Password field on the login form.
        tblUsers = The name of the table which stores the user details.
        Password = Name of the Password column in the user table.
        UserName = Name of the username column in the user table.
        Main Menu = Name of my menu form.

        Hope that helps.

        Adam.

        Comment

        • Aaitaman Tamang
          New Member
          • Jul 2011
          • 22

          #5
          Adam,
          Thanks for reply. I have the same code alreay in used and it is working fine as intended but i was looking for something else where i can use vba to disable and enable the secondary menu base on valid and invalid user login. I certain that you can help me on this. I am give you screen print to easy understanding of my needs.

          I am using my own menu bar called "Incident Reporting" from Tool-Start Up and menu bar. note: I am not using access orginal menu bar and also added form called "UserF" which is user login form as start up when db opens. When i open my db the "userF" which user login form will appear first with my menu bar. But there is still access to jump to menu bar without login. I don;t user directly jump to menu bar and interact with other forms. I want user to first logged in and then able to use menu bar for menu items. if not menu should be disable

          Thanks,
          Last edited by Niheel; Jul 18 '11, 10:21 AM. Reason: Post your screenshots on the site, don't request for emails.

          Comment

          • Adam Tippelt
            New Member
            • Nov 2010
            • 137

            #6
            Are you talking about users being able to use the Navigation Pane to access other forms?

            If this is the case, go to:

            File (Office Button) -> Access Options -> Current Database -> Navigation

            and untick the Display Navigation Pane option. You will need to restart the application for it to take effect, but it will mean the only way to gain access to the menu is by logging in.

            This is an option that I normally leave enabled on a prototype copy, as you need it during development, but is something you should disable when handed over for actual use by users.


            If this is not what you mean, please elaborate on how exactly user's are jumping to the menu bar without logging in.

            Adam.

            Comment

            • Aaitaman Tamang
              New Member
              • Jul 2011
              • 22

              #7
              Adam, I will try this by using but i am using 2003 and there is no option as said. should be another way on 2003.

              Its little comlicated but i should be able to get help of my needs soon.

              Thanks a lot for your help.

              Comment

              • Adam Tippelt
                New Member
                • Nov 2010
                • 137

                #8
                Ah right, I was under the assumption that it was 2007.
                I do not know 2003 very well, but I imagine the options exist somewhere on 2003 to disable whatever 2003's equivalent is of the navigation pane.
                Try looking under Tools -> Options or similar areas, or perhaps someone with knowledge of 2003 can step in.

                Comment

                • Aaitaman Tamang
                  New Member
                  • Jul 2011
                  • 22

                  #9
                  Adam,

                  End of the day i have fixed it.

                  Thanks a lot for helo & information shared with me.

                  Good day!

                  Comment

                  Working...