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-11T16:21:22+00:00

    Please,how do I locate the VB editor

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-06-11T16:10:39+00:00

    Is it possible that you don't have a reference set to DAO?  That would be very unusual, but just in case, in the VB Editor window, on the menu line at the top, click Tools -> References, and verify that one of the checked references at the top of the list is either "Microsoft Office <version> Access database engine Object Library" or (for Access 2003 or earlier) "Microsoft DAO 3.6 Object Library".

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2018-06-11T15:54:23+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/

    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
  4. Anonymous
    2018-06-11T15:52:58+00:00

    I have tried "Dim rs As DAO.Recordset " as you instructed, the error still persist.

    Was this answer helpful?

    0 comments No comments
  5. ScottGem 68,830 Reputation points Volunteer Moderator
    2018-06-11T15:43:44+00:00

    Try Dim rs As DAO.Recordset

    Was this answer helpful?

    0 comments No comments