Monday, November 12, 2012

VB6 Tutorial - Creating Login Form with MS Access 2007 as Database



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..



After you done with your table login close it first. To create our login form with VB6:

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.




Right click the connection1 and select properties then put the following settings:
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!






15 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thank you very very much for sharing

    ReplyDelete
  3. OH MY GOSH! THANK YOU SO MUCH FOR SHARING THIS VERY HELPFUL INFORMATION. GODBLESS!

    ReplyDelete
  4. Sir I have a question, How to put password on my MS ACCESS database?

    ReplyDelete
  5. It's helpful but there's a bit problem. when i create another form as "main form" the login form you made doesn't close it self once i login. please help mewith that.

    ReplyDelete
  6. It is showing error in
    If Text1 = !username And Text2 = !password Then
    help please

    ReplyDelete
  7. What does argument not optional mean

    ReplyDelete
  8. Hello, The code actually works and thanks but I want to ask there is slight a problem for me, When I login it is successful, when I press okay and use dummy (to test the invalid password thing) it says 3705 error a helping hand would be very appreciated. Thanks (Contact me in lukeylol215 - skype or Emmar U. Ruga(fb pumpkin prof pic))

    ReplyDelete
  9. very helpful.. thanks so much
    just one question, how can i limit the wrong log in attempts to 3 tries only

    ReplyDelete
  10. when i tried to connect access database it says unrecognized database format.... plz hlp me

    ReplyDelete
  11. Hey... great tutorial... Nice explanation with images.. Thanks..

    ReplyDelete
  12. Vimeo | Vimeo
    Vimeo is a free, entertaining and youtube converter educational resource for learners and educators. Find video tutorials, videos, and more on Vimeo. Rating: 5 · ‎3 votes

    ReplyDelete