Saturday, April 21, 2018

Login form with adodc connection to MS-Access in vb6.0 tips

Login form with ADODC connection with MS-Access in vb6.0 easy tips

In this post, we will describe step by step instruction to design login form with ADODC connection to Ms-Access in visual basic 6.0. 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 Login secure process.

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

(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


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.

Get or show 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

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
  IfPass_Txt.Text = recset!Password Then

   MsgBox "Login Succesful."

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

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


End Sub
This code will close your running application.

There is tips to create Login Form and connect with database through ADODC in visual basic 6.0 with easy tips through SKOTechLearn.

Database record in MSHFlexGrid through ADODC in vb6.0