Share via

Login Code Problem in Access

Anonymous
2018-06-11T14:54:25+00:00

Hello there, please someone should help me on this code problem, I am working on how to login to a form main menu using a login screen to achieve gain access,I have created a table called "Admin" and  a "login form" I created textboxes for "user name and Password" with the following codes:

Private Sub btnLogin_Click()

   Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset("tblAdim", dbOpenSnapShot, DbReadOnly)

   rs.FindFirst "UserName='" & Me.txtUsername & "'"

   If rs.NoMatch = True Then

  Me.lbWrongUser.Visible = True

  Me.txtUsername.SetFocus

Exit Sub

End If

Me.lbWrongUser.Visible = False

 If rs!Password <> Me.txtPassword Then

  Me.lblWrongPass.Visible = True

  Me.txtPassword.SetFocus

    Exit Sub

 End If

  Me.lblWrongPass.Visible = False

  DoCmd.OpenForm "frmMainMenu"

  DoCmd.Close acForm, Me.Name

  End Sub

     But the exception I got is :" user defined type not defined" Please tell me what to do.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

19 answers

Sort by: Most helpful
  1. Anonymous
    2018-06-11T15:41:20+00:00

    Private Sub btnLogin_Click()    ......................................... this line on yellow colour

       Dim rs As Recordset              ........................................   this line is blue highlighted

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-06-11T15:23:57+00:00

    Private Sub btnLogin_Click()    ......................................... this line on yellow colour

       Dim rs As Recordset              ........................................   this line is blue highlighted

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,830 Reputation points Volunteer Moderator
    2018-06-11T15:13:57+00:00

    Please indicate what line is giving you the error.

    You might also want to take a look at my blog on Login Security with VBA. https://scottgem.wordpress.com/2010/01/12/creat... It discussed, with sample code, ways to secure an application with a login. personally, I would not use Find as you are doing it. I would use a combobox so the user can select their name. That may not be your problem, but I think its a cleaner way to do it.

    Please Note: This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2018-06-11T15:11:22+00:00

    I suggest you check your spelling of the table, field, and control names.  I notice that you say you have a table named "Admin", but the table name you are opening is "tblAdim".  I also notice that your code calls your wrong-user label "lbWrongUser", but it calls your wrong-password label "lblWrongPass" -- the prefixes are inconsistent, so maybe one of them is wrong.

    If you don't find any misspellings, what exact line raises the error?

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2018-06-11T15:08:13+00:00

    Which line is highlighted as problematic.

    You may also like to review

    http://www.devhut.net/2012/12/21/ms-access-login-form/

    Was this answer helpful?

    0 comments No comments