Dim txtloginname As New TextBox txtloginname.Location = New Point(100, 100) txtloginname.Size = New Size(200, 60) Me.Controls.Add(txtloginname) Dim txtpassword As New TextBox txtpassword.Location = New Point(100, 140) txtpassword.Size = New Size(200, 60) Me.Controls.Add(txtpassword) Dim btnLogin As New Button btnLogin.Text = "Log In" btnLogin.Location = New Point(100, 200) btnLogin.Size = New Size(75, 25) Me.Controls.Add(btnLogin) AddHandler btnLogin.Click, AddressOf LoginProcess Private Sub LoginProcess() Dim connect As New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data source=Database genk.mdb;") connect.Open() Dim cmd As OleDbCommand = New OleDbCommand cmd.CommandText = "SELECT * FROM Users WHERE Username = '" & txtloginname.Text & "' AND Password = '" & txtpassword.Text & "' " cmd.Connection = connect Dim odr As OleDbDataReader = cmd.ExecuteReader() If (odr.Read = True) Then MessageBox.Show("Access granted") Dim MenuPage As New Menu_Page MenuPage.Show() Me.Hide() Else MsgBox("Incorrect Username or Password. Please try again", MsgBoxStyle.Critical, "Error") End If End Sub
I have created a login form which only allows access the valid users. However when I am trying to validate the username and password enetered when the user clicks the Login button (btnLogin). However I am unable to pass through the username and password in the Select statement, entered by the user beccause it gives me an error that 'txtloginname' and 'txtpassword' is not declared in the LoginProcess Private Sub. How do I declare the texboxes i coded into the LoginProcess Private sub for it to work?
Last edited by a moderator: