Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116

    Login error

    I have 2 issues with my login form

    Issue 1. In the onClick event of the login button this is the code which is executed:

    Private Sub btnLogin_Click()
    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.cboEmployee.SetFocus
    Exit Sub
    End If
    'Check to see if data is entered into the password box


    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
    MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
    Me.txtPassword.SetFocus
    Exit Sub
    End If
    'Check value of password in tblEmployees to see if this
    'matches value chosen in combo box
    MsgBox (Me.txtPassword.Value)
    MsgBox (Me.cboEmployee.Value)
    If Me.txtPassword.Value = DLookup("strEmpPassword", "Login", "[lngEmpID]=" & Me.cboEmployee.Value) Then
    lngMyEmpID = Me.cboEmployee.Value
    'Close logon form and open splash screen
    DoCmd.Close acForm, "F_Login", acSaveNo
    DoCmd.OpenForm "F_Products"
    Else
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
    "Invalid Entry!"
    Me.txtPassword.SetFocus
    End If
    'If User Enters incorrect password 3 times database will shutdown
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
    MsgBox "You do not have access to this database.Please contact admin.", _
    vbCritical, "Restricted Access!"
    Application.Quit
    End If

    End Sub


    The problem is when I click login, I get the error: "The expression you entered as a query parameter produced this error"

    Any idea why??


    Issue 2: I want the other forms and tables to be hidden until the user logs in. Right now, all the tables and forms are visible even before the user can log in.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    You should step debug to identify the line that throws the error. Set a breakpoint at the beginning of the procedure. Follow the code as it executes, one line at a time. Right now I can only guess that the problem is with the DLookup. Is strEmpPassword a variable? You don't show it declared in the code. If this is a variable why is it used as the fieldname of the search field argument?

    Also, two uses of MsgBox is not correct. MsgBox can be used two ways. One is a simple popup and users can only respond to an Okay button. The other is as a function. The function version requires parenthesis. You are using the function version and this should error because functions have to on one side of an expression. I don't think you need these two MsgBoxes anyway.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Hey,
    Those 2 msgboxes were just to check if the values for password and username were retrieved properly. I should have removed it.

    strEmpPassword is a field name in the table. lngEmpID is another field and it is an autoNumber. When I debug there are no values stored for these 2 variables. I get strEmpPassword=Empty and lngEmpID=Empty.

    Btw, I have another error. In the next line: "lngMyEmpID = Me.cboEmployee.Value", I get the error 'type conversion mismatch'. cboEmployee is the combo box for the userName in the form. Can you let me know why I have this error?
    Last edited by accessnewb; 07-26-2011 at 07:34 AM. Reason: Made a mistake while explaining

  4. #4
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Hi the error is solved! The problem was actually not with the code but with the combo box for userName in the form. The select query was not right and now it is fine!

    Anyway, can anyone please let me know how I can hide tables/forms until the user logs in? Right now, the user can see all the forms/tables even before he can log in.

    Also, would be great if anyone can let me know how to manipulate access for certain users. For example, if the user is an admin then he must have access to all the tables/forms. If he is from marketing dept, then he can have access to only certain forms or if he is from HR, then only certain forms..well..you get the idea :-)

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Hiding the navigation pane is a setting of the project. Click Office button then Access Options>CurrentDatabase, uncheck Display Navigation Pane. Only project designer should have access to the navigation pane. Holding the shift key when opening project will override these settings.

    Access to forms would have to be controlled by VBA code. I presume you have a switchboard (main menu) form. When user logs in, use their ID to control which menu items are enabled for them.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    ... and you should have converted your front end to MDE/ACCDE to protect your forms, modules, macros etc from user to modify.

  7. #7
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Quote Originally Posted by June7 View Post
    When user logs in, use their ID to control which menu items are enabled for them.
    err..how do i do that?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Here is I do it for a form called Administration that is opened from main Menu form. The code looks for my initials and if not found two buttons are disabled for all other users. Your situation is probably more complex.
    Code:
    Private Sub Form_Load()
    If Form_Menu.tbxUser <> "HJF" Then
    Me.btnTest.Enabled = False
    Me.btnMaterial.Enabled = False
    End If
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    @June: If I want to hide forms for certain users, then do I use the code "Forms!formName.enabled = false ?

    Also, I have another super dumb doubt. In your code is 'Form_Menu' the name of your form? Well, it should be, but just checking

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Yes, Menu is the name I gave to my form. The Form_ prefix is added on because this is VBA code. Look at the list of objects in the VBA code editor. You will see prefixes to all forms and reports.

    Alternative syntax using the Forms collection would be: Forms!Menu.tbxUser

    By 'hide forms' do you mean not show in the Navigation pane? I don't know anyway to do that. I simply hide the pane from all users.

    I don't hide forms, I just don't allow them to be opened by unauthorized user by disabling the command button that would normally open the form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Quote Originally Posted by June7 View Post

    I don't hide forms, I just don't allow them to be opened by unauthorized user by disabling the command button that would normally open the form.

    How do I do that?

  12. #12
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    @June: oh wait I know how to do that! I mean disable the command button for forms! No need to reply to that and thanks a lot! you've been really helpful

  13. #13
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Quote Originally Posted by June7 View Post
    Hiding the navigation pane is a setting of the project. Click Office button then Access Options>CurrentDatabase, uncheck Display Navigation Pane. Only project designer should have access to the navigation pane. Holding the shift key when opening project will override these settings.
    Just one more tiny last question. When I uncheck display navigation pane, then it is permanently hidden. I would like for it to be hidden when the login form is open and after successful login, the forms/tables will be visible in the navigation pane. I have seen this example on web pages a couple of times, but the source code is never revealed

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    This hides the navigation pane:
    DoCmd.RunCommand acCmdWindowHide

    This will reveal the navigation pane:
    DoCmd.SelectObject acTable, , True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    It worked after I made slight changes to the code. This is what I used:

    Private Sub Form_Load()
    isNavWindowVisible = True
    If isNavWindowVisible = True Then
    DoCmd.SelectObject acTable, "Login", True
    DoCmd.RunCommand acCmdWindowHide
    End If

    End Sub

    I set a public variable isNavWindowVisible as boolean and in the formLoad event set it to true.

    In the login button click event, I again coded: DoCmd.SelectObject acTable, , True

    Is this ok?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. login tracking
    By itsmemike in forum Access
    Replies: 8
    Last Post: 09-18-2010, 08:05 AM
  2. Auto Login
    By gripper in forum Programming
    Replies: 1
    Last Post: 08-30-2010, 06:26 PM
  3. Login VBA
    By mjhopler in forum Forms
    Replies: 3
    Last Post: 02-11-2010, 02:28 AM
  4. app.login
    By seen in forum Access
    Replies: 3
    Last Post: 07-18-2009, 01:19 AM
  5. Database Login Error
    By narasareddy in forum Access
    Replies: 0
    Last Post: 08-30-2008, 12:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums