Login Form with Adodc Connection to MS-Access in VB6.0 Tips

Whenever we design an application in VB, we always use to secure our application by adding Login Form with username and Password. And many concern use their application with Create Login Form for secure process. Here, you will also learn tips to Connect Login Form With Database in VB.

In this post, SKOTechLearn will describe step by step instruction to Design Login form with ADODC Connection to Ms-Access in visual basic 6.0.

There is following example of Login Form in VB6.0.
Image of Login Form
Login Form
We will follow 3 Steps.

  1. Create Table in Database 
  2. Design Login Form
  3. Connect Login Form with MS-Access

So, Let's start with above given steps to Create Login Form with Database Connectivity.

(1). Create Table in Database: 

First, we have to process on create and design a table in MS-Aceess. Suppose, we create a database in "C:\" drive with name ‘LoginDB.mdb’.

Open ‘LoginDB.mdb’ database and go to "Create" menu and click on "Table" option. After that go to "View" option and select "Design View" option.

When you click on "Design View" option, "Save as" box will appear. Type table name in "Save as" input box. Suppose, we input table name as ‘LoginTbl’.

After that open ‘LoginTbl’ in 'Design View' and type ‘Field Name’ as ‘Username’ and ‘Password’. Then save it. Suppose, we input username as ‘skotech’ and password as ‘abcd1234’.

Setup ADO Data (ADODC) component in vb6.0

Steps:

LoginDB.mdb (Open) >> Create >> Table >> View >> Design View >> Save As >> Field Name

The following image describe step by step instruction to Create a Table in MS- Access.
Login Table for Login Form
Create Login Table


(2). Design Login Form :

For designing this form through Visual Basic 6.0, you have to drag 2 Label, 2 Textbox and 2 command button.

Suppose, we drag 2 Label from "Toolbox" and type its caption as ‘Username:’ and ‘Password:’.

Drag 2 Textbox and type its Name as ‘User_Txt’ and ‘Pass_Txt' and set ‘PasswordChar’ as ‘*’ from ‘Property’ window.

Drag 2 Command button set its caption as ‘Login’ and ‘Close’. And drag ‘ADODC’ control. Setting Property of every controls describe bellow.

 Displaying or Showing ListView Data in TextBox in VB6.0

Controls Properties for Login Form
Controls Properties
The above image described the controls properties, which have to define at design time.


(3). Connect Login Form with MS- Access :

Now, we have to type code in control’s events as described below.

Database Connection Code:
'Global define connection sanjeev

Public conn1 As New ADODB.Connection

Private Sub Form_Load()

 conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\LoginDB.mdb;Persist Security Info=False"  

End Sub

In above given code instruction, first we have to define the Connection with MS-Access database. We have to global define connection object as ‘conn1’. Then open connection to its Load events.

Selected items Edit or Delete from Listview

Code:
Private Sub Login_Btn_Click()

 Dim recset As New ADODB.Recordset
'recset define the record of table
 recset.Open "SELECT Count(Username) AS CountOfUser, Password FROM LoginTbl WHERE (((Username)='" & User_Txt.Text & "') AND ((Password)='" & Pass_Txt.Text & "')) GROUP BY Password;", conn1, adOpenStatic, adLockReadOnly

 If recset!CountOfUser <> 0 Then
    If Pass_Txt.Text = recset!Password Then

      MsgBox "Login Succesful."

    Else
      MsgBox "Wrong Input, try again"
      Pass_Txt.SetFocus
      'Focus on Pass_Txt, when wrong Input
    End If

 Else
    MsgBox "Wrong Username or Password"
    User_Txt.SetFocus
    'Focus on User_Txt, when wrong input in both text box    
 End If 
   recset.Close  
   Set recset = Nothing  
End Sub
You have to type this code on ‘Login_Btn’ click event.

Close button Code:
Private Sub Close_Btn_Click()

  conn1.Close
  End

End Sub

This code will close your running application.

These are the tips to Create Login Form with Database Connection through ADODC in Visual Basic 6.0 with easy tips described through SKOTechLearn.

Database record in MSHFlexGrid through ADODC in vb6.0

1 comment: