Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection to Access 97 database

Status
Not open for further replies.

suzreid

Technical User
Sep 26, 2000
59
GB
Help!!!

I am trying to write VB6 code that will be used to verify that user names and passwords are valid.I have an Access 97 database that contains a table that holds the valid usernames and passwords.

The VB has a form where the user types in his username and password. When the OK button on this form is clicked I need the application to connect to the database and verify that the username and password entered on the form is contained in the table in the database.

I have no idea how to connect to the database to verify this information.

Can anyone help??

Suz
 
The standard way to do this is via ADO.
Try the following and change Database names and table name to suit your situation.

Code:
dim cnDb as ADODB.Connection
dim rsResults as ADODB.Recordset
dim strSelectSQL as string
dim blnValidLogin = Boolean

set cnDB = New ADODB.Connection
cnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\MyFolder\MyDatabase.mdb"
cnDB.Open

strSelectSQL = ""SELECT login_id FROM logins WHERE username = '"
strSelectSQL = strSelectSQL & trim$(txtUsername.text)
strSelectSQL = strSelectSQL & "' AND password = '"
strSelectSQL = strSelectSQL & trim$(txtPassword.text)
strSelectSQL = strSelectSQL & "';"

set rsResults = New ADODB.Recordset
rsResults .ActiveConnection = cnDB
rsResults.Source = strSelectSQL
rsResults.Open

if rsResults.RecordCount = 1 then
    blnValidLogin = True
else
    blnValidLogin = False
end if

set cnDB = Nothing
set rsResults = Nothing

Hope this helps.

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top