Login Form

Kenta

Member
Joined
Mar 17, 2012
Messages
21
Programming Experience
Beginner
Hello Everyone,

I am doing a Login Form that should be connected to MS Access 2010, and I had my guide from the following video:
Visual Basic Login Form Using Access Database Part 1 - YouTube

But it seems that there's no established connection ... ! The following is the code, I believe that the problem is with the extension of the database; where my database's extension is [ .accdb ], how can I fix it?

 Public Class Form1

    Dim loginError As String 'Problem with the 'login.

    Public Function Login()
        Dim DBConn As New ADODB.Connection 'Connection to the DB
        Dim User As New ADODB.Recordset 'passing out the args
        Dim UserName As String 'our query
        Dim UserDB As String 'get the user name
        Dim PassDB As String 'get the password

        Dim UserFound As Boolean 'some kind of a loop to check if the user exists in the database

        DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source = '" & Application.StartupPath & "\LoginDB.accdb'")
        User.Open("UserTable", DBConn.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

        UserFound = False
        Login = False

        UserName = "UserName = '" & TextBox1.Text & "'"
        Do
            User.Find(UserName)
            If User.BOF = False And User.EOF = False Then
                UserDB = User.Fields("UserName").Value.ToString
                PassDB = User.Fields("Password").Value.ToString
                If UserDB <> TextBox1.Text Then
                    User.MoveNext()

                Else
                    UserFound = True
                    If PassDB = TextBox2.Text Then
                        User.Close()
                        DBConn.Close()
                        Return True

                    Else
                        loginError = "Invalid Password, Please Check it"

                        User.Close()
                        DBConn.Close()
                        Return False

                    End If
                End If

            Else
                loginError = "Invalid Username, Please Check it!"

                User.Close()
                DBConn.Close()
                Return False

            End If
        Loop Until UserFound = True
        User.Close()
        DBConn.Close()
        Return False


    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Login() = True Then
            MessageBox.Show("Logged On!", "Login Message")
        Else
            MessageBox.Show(loginError, "Login Message")

        End If
    End Sub
End Class

 
Last edited by a moderator:
Argh! I hate it with a passion when people teach new VB.NET developers how to do things like they used to be done in VB6. You should get rid of that old ADO rubbish. You're using VB.NET so use ADO.NET.

Here's a link to a simple example of my own that shows how to provide a login dialogue for a WinForms app and it provides a link to another thread that shows how to actually validate the credentials.

WinForms Login

The data access code is written for SQL Server but all you need to do is use OleDb instead of SqlClient, e.g. OleDb.OleDbConnection instead of SqlClient.SqlConnection, and use the same connection string as you have above. Rather than using string concatenation with Application.StartupPath though, use "|DataDirectory|" in your connection string to represent the path of the program folder.
 
Argh! I hate it with a passion when people teach new VB.NET developers how to do things like they used to be done in VB6. You should get rid of that old ADO rubbish. You're using VB.NET so use ADO.NET.

Here's a link to a simple example of my own that shows how to provide a login dialogue for a WinForms app and it provides a link to another thread that shows how to actually validate the credentials.

WinForms Login

The data access code is written for SQL Server but all you need to do is use OleDb instead of SqlClient, e.g. OleDb.OleDbConnection instead of SqlClient.SqlConnection, and use the same connection string as you have above. Rather than using string concatenation with Application.StartupPath though, use "|DataDirectory|" in your connection string to represent the path of the program folder.

This is really going to be a great of help... yet when I run your previous project I get this error : "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine." Do you have any idea about it? Is there's something I need to modify?
 
This is really going to be a great of help... yet when I run your previous project I get this error : "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine." Do you have any idea about it? Is there's something I need to modify?

The usual reason for that is that you are developing on a 64-bit machine and your project is targeting the Any CPU platform, which means that your app will be running in 64-bit mode. The Jet OLE DB provider is only available in 32-bit form. As a result, you must set the target platform for your project to x86, to force your app to run in 32-bit mode on all systems.
 
The usual reason for that is that you are developing on a 64-bit machine and your project is targeting the Any CPU platform, which means that your app will be running in 64-bit mode. The Jet OLE DB provider is only available in 32-bit form. As a result, you must set the target platform for your project to x86, to force your app to run in 32-bit mode on all systems.

Yes! thank you for the assist, but there's something else... now I don't need just a login form but I want to provide a way that once the user register, a folder is created for them and is only accessible by the user who created it... can I do that using a vb.net??
 
hi sorry to post but i am new here and i cant figure out how to post my own question, but i see everyone else posted questions. if someone can explain me that would be great .thank you :)
 
Yes! thank you for the assist, but there's something else... now I don't need just a login form but I want to provide a way that once the user register, a folder is created for them and is only accessible by the user who created it... can I do that using a vb.net??

That's a new question and belongs in a new thread. Just so @sanjaylp knows, that's is accomplished using the Post New Thread button at the top of the appropriate forum.
 
Back
Top