In this Visual Basic 6 Tutorial series, you will learn how to create a log in form with using Data Environment as your database. There are many ways to create database, but for me using Data Environment is the easy one. Try to continue reading and see it for yourself.
Tutorial:
Firstly, we will create our database using MS Access 2007, so open up your MS Access 2007 then select the Blank Database. Enter your desired database name then click the folder like icon to select the location where your database save, choose the 2002-2003 format then save. then click create to build your database. Click the image below to view the original size..
Now, close your database and open it again.
To save the login info we should make a table for it, so click Create and select Table Design
type username and password the select text for their data types
Save your table by hitting ctrl + s on your keyboard and name it as "tbl_login", click no for the primary key.
Close your table design view and open up your tbl_login to put some entry
So our table has been made, it's time to put some info to it, type your desired login info (username, password) as many as you want. Always remember to save your table every time you made a changes. Your table should look like this..
Open up your Visual Basic 6 Studio and choose Standard EXE.
Add Data Environment to your project by navigating Project>>Add Data Environment and Data Environment Window should show up.
Click the image below to view the original size..
Provider: Microsoft Jet 4.0 OLE BD Provider
Connection: Locate your Database from your computer
Advanced: Unchecked all the boxes under access permission except ReadWrite
Then click Ok to build your database connection
After that we need to add our tbl_login as command, so right click to the connection1 and select add command, Command1 should show up under connection1. Right click to it then type cmd_login on Command Name, choose Table in Database Object then select tbl_login in Object Name and on the Advance Tab, set the lock type to Optimistic so you can read and write to it.
Design your login form by adding two textboxes, 2 command buttons, 3 captions for the title, username and password captions. It should look like similar to this..
Double click the Login button and add this code
With DataEnvironment1.rscmd_login 'opening the tbl_login
.Open
.MoveFirst
While Not .EOF 'scan all entry under tbl_login
If Text1 = !username And Text2 = !password Then
a = MsgBox("Username and Password Accepted, Welcome!", vbInformation) 'login accepted
Exit Sub
Else
.MoveNext 'move to another row
End If
Wend
.Close 'close tbl_login
a = MsgBox("You have entered an invalid username/password", vbCritical) 'login detaits not matched
End With
And there you are, you have created a simple login form using MS Access 2007 as your database.
Drop some comments if you have some question and I give it a shot as soon as possible. Enjoy!