borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (how to access field in excel in the program)Next Topic (Entering text in an external application) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Creating Login Program
Poster Message
everard
Level: Trainee

Registered: 24-03-2006
Posts: 1

icon Creating Login Program

I just want to create a login program. My problem is how can I connect VB to MSAccess and what is the code I'll use to verify the username and password that was stored in database (MSAccess)?

It is just a simple login program having ten accounts stored in the database.

____________________________
Beginner...

24-03-2006 at 03:42 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 536
icon Re: Creating Login Program

Hi,
Take a look at this current thread about connecting VB6 app. to MS Access DB.
http://www.andreavb.com/forum/viewtopic_6842.html

All you need then is a table in the database with UserName and Password fields. Create a Form in VB with 2 textboxes - (UserName and Password) and a button marked "LogIn". Then in the button_Click Event connect to your Database and open a recordset based on your Users table. The best way would be with a SQL Query with a "WHERE" clause that looks for a match between what your users type into the Form and whats in the table.



Dim strCNN As String
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strPath As String
Dim strPASS As String, strName As String, strSQL As String

strPath = "\\MyServerName\ShareName"

strCNN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & "\MyDatabase.mdb;Persist Security Info=False;Jet OLEDB:" _
& "Database Password=MyDatabasePassword_IF_SET"

Set cnn = New ADODB.Connection
cnn.CursorLocation = adUseClient
cnn.Open strCNN

strPASS = Me.txtPassword.Text
strName = Me.txtName.Text

strSQL = "SELECT users.user_id, users.user_name, users.user_password " _
& "FROM users WHERE (((users.user_password)='" & strPASS & "') And ((users.user_name)='" & strName & "'));"

Set rst = New ADODB.Recordset
rst.Open strSQL, cnn, adOpenDynamic, adLockOptimistic


If Not (rst.BOF And rst.EOF) Then
' there are Password records so allow access
Else
' there are no Password records so do not allow access
End if

'Close the recordset and free up memory
rst.Close
set cnn = Nothing




____________________________
multi-tasking - the ability to hang more than one app. at the same time.

24-03-2006 at 02:10 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Creating Login Program
Previous Topic (how to access field in excel in the program)Next Topic (Entering text in an external application) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder