Hi there,
I am new to VB and is trying to create a login application. I currently have a form with two text boxes (txtUserName and txtPassword) and a submit button, right now I am able to validate the user name and password but I have to hard coded both of the UserName and Password in my code(not very efficient). I want to be able to validate users' input against my database, I have a table in Access with the following fields: Id, UserName, Password. I know I need to write a SQL statement but I don't know how to compare the result of the query to the value of the 2 text boxes. I am posting what i have, can someone be kind enough to take a look and point me in the right direction? TIA.


frmLogIn
Option Explicit

Private strPassword As String

Private Sub cmdLogIn_Click()
If (UCase(txtName.Text) = "SUNSHINE" And UCase(strPassword) = "HELLO") Or _
(UCase(txtName.Text) = "SNOWY" And UCase(strPassword) = "TEST") Then
frmMenu.Show
Unload Me
Else
MsgBox "Sorry" & First(txtName.Text) & ", incorrect password please try again.", vbApplicationModal, "Incorrect Password"
Call ClearText
End If

End Sub

Private Sub cmdReset_Click()
End
End Sub

Private Sub txtPassword_Change()
Dim I As Integer
For I = 1 To Len(txtPassword.Text)
If Mid(txtPassword.Text, I, 1) <> "*" Then
strPassword = strPassword + Mid(txtPassword.Text, I, 1)
txtPassword.Text = Mid(txtPassword.Text, 1, I - 1) + "*"
End If
Next I
End Sub

Public Function First(Name As String) As String
Dim I As Integer
For I = 1 To Len(Name)
If Mid(Name, I, 1) = "" Then
First = Mid(Name, 1, I - 1)
Exit Function
End If
Next I
First = Name
End Function

Private Sub ClearText()
txtName.Text = ""
txtPassword.Text = ""
strPassword = ""
txtName.SetFocus
End Sub