Login Form is very important for any application. We have designed this Login form in VBA User form and connected with MS Access Database. We have used ADODB Connection to connect with MS Access Database. To create the design of this Login form we have taken the support of Microsoft Power Point also.
Click here to learn more about ADODB Connection.
Below is the snapshot of MS Access database table –
To use the ADODB connection you need add Microsoft ActiveX Data Objects reference.
- Go to the Visual basic Editor (Press Alt+F11)
- Go to Tools >> References>> Microsoft ActiveX Data Objects 2.8 Library
Below is the code of User login procedure which can be called on Login Button-
Option Explicit Sub User_Login(User_Id As String, Password As String) Dim cnn As New ADODB.Connection Dim rst As New ADODB.Recordset Dim qry As String cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\Database\Database.accdb" qry = "SELECT * FROM TBL_UM WHERE User_id = '" & User_Id & "'" rst.Open qry, cnn, adOpenKeyset, adLockOptimistic If rst.RecordCount = 0 Then MsgBox "Incorrect User Id", vbCritical ElseIf rst.Fields("Password").Value = Password Then MsgBox "Login successfully", vbInformation Else MsgBox "Incorrect password", vbCritical End If rst.Close cnn.Close End Sub