Hii all this is my lab program (vb program to validate the user name and password from the database and display the appropriate message) use Data control

i getting Run- time error '-2147467259 (80004005)' Could not find file 'C:\Program Files (x86)Microsoft Visual Studio\VB98\Account.mdb

My code is

Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection

Private Sub cmdexit_Click()
    MsgBox "do u really want to exit", vbInformation + vbOKOnly, "login"
    If vbOK Then
        End
    End If
End Sub

Private Sub cmdlogin_Click()
    If Text1.Text = "" Then
        MsgBox "enter the username", vbInformation + vbOKOnly, "login"
        Text1.SetFocus
        Exit Sub
    End If
    If Text2.Text = "" Then
        MsgBox "enter the password", vbInformation + vbOKOnly, "login"
        Text2.SetFocus
        Exit Sub
    End If
    If Text1.Text <> "" And Text2.Text <> "" Then
        If rs.State = 1 Then
            rs.Close
        Else
            rs.Open "select * from login where username='" & Text1 & "' and password= '" & Text2 & "' ", conn, adOpenDynamic, adLockOptimistic, adCmdText
        End If
        If rs.EOF = True Then
            MsgBox "invalid username and password", vbCritical + vbOKOnly, "login"
            Text1.Text = ""
            Text2.Text = ""
            Text1.SetFocus
        Else
            MsgBox "username and password correct", vbInformation + vbOKOnly, "login"
        End If
    End If
End Sub

Private Sub Form_Load()
    conn.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\ Account.mdb;persist security info = false"
End Sub

Edited 8 Months Ago by Reverend Jim: Corrected code formatting

Are you personally sure that Account.mdb exists in Application Folder ? If so, please check the spelling of that mdb file.

i have not created any application folder bro..... am new to dis vb6
can u guide me how to create Account.mdb file in vb6 plz.... itz my lab program

In which folder the exe file of your project is residing, this folder is called Application Folder of that particular project. At the time of creation of a project you can set the project /application folder fo that project.
Here vb98 is the project folder.

You can create your access (.mdb) database file by using MSAccess or through vb6 Tools menu. you can save it any where in your HDD. To call database you must have to write the correct path and database file name.

i hav changed the code
now am getting this error
Run-time error'-2147467259(80004005)': [Microsoft][ODBC Driver Manager]Data Source name not found and no default driver specified
Plz tel me how attach the mdb file

Private Sub cmdlogin_Click()
If txtusername.Text = "" And txtpassword.Text = "" Then
        MsgBox "All fields are Mandatory", vbOKOnly, "Login"
        Exit Sub
End If

If txtusername.Text = "" And txtpassword.Text <> "" Then
        MsgBox "User Name not found", vbOKOnly, "Login"
        Exit Sub
End If

If txtusername.Text <> "" And txtpassword.Text = "" Then
        MsgBox "Password not found", vbOKOnly, "Login"
        Exit Sub
End If

Adodc1.Refresh
Adodc1.Recordset.MoveFirst
While Not Adodc1.Recordset.EOF
     If txtusername.Text = Adodc1.Recordset.Fields(0) And txtpassword.Text = Adodc1.Recordset.Fields(1) Then
        MsgBox "you have logged in Sucessfully", vbOKOnly, "Login"
        txtusername.Text = ""
        txtpassword.Text = ""
        Exit Sub
    Else
        Adodc1.Recordset.MoveNext
   End If
Wend
MsgBox "Login Failed", vbOKOnly, "Login"
txtusername.Text = ""
txtpassword.Text = ""

End Sub

Private Sub cmdstop_Click()
MsgBox " You are not Authorised to use this Software", vbOKOnly, "Login"
End
End Sub

Your database connections should be

Private Sub Form_Load()
        conn.Open "Provider=microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\ Account.mdb;"
    End Sub

You can use also DataDirectory Keyword if database resides in your application folder.

Private Sub Form_Load()
    conn.Open "Provider=microsoft.jet.oledb.4.0;Data Source=|DataDirectory|\ Account.mdb;"
End Sub
This article has been dead for over six months. Start a new discussion instead.