Home>Blogs>VBA>Login Form for Excel VBA based Application
VBA Login Form

Login Form for Excel VBA based Application

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 –

MS Access Table
MS Access 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
Add Reference
Add Reference


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
MsgBox "Incorrect password", vbCritical
End If


End Sub

Below is the snapshot of Login form-

VBA Login Form
VBA Login Form

Click here to download the Practice files.

Watch the step by step video tutorial:

Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!