Visual Basic Simple Login Connected To Database

Visual Basic 6.0 Simple Login Connected to Database














Login Code:


Dim ctr As Integer

Private Sub CmdLogin_Click()
Static ctr As Integer

    Set rs = MySQL("SELECT * FROM  tblUserAccount")

    If txtUsername.Text = rs!username And txtPassword.Text = rs!Password Then
        
        MsgBox "WELCOME ADMIN USER", vbInformation
        frmMain.Show vbModal
    
    Else
        MsgBox "NOT valid Username/Password", vbCritical
        txtUsername.Text = ""
        txtPassword.Text = ""
        txtUsername.SetFocus
        ctr = ctr + 1
        

End If
    If ctr = 3 Then
       
    MsgBox "You have attempted to Login 3 Times in the system. " & _
                        "Please call Programmer for Assistance " _
                        , vbCritical, "Warning Information"
    
    Unload Me
    
    End If

End Sub

Cancel Code:


Private Sub CmdCancel_Click()
Unload Me
End Sub



Create your DATABASE:Like This and save it by (jams)


Create a Module: Just Copy Paste This


Public rs As New ADODB.Recordset
Public Function MySQL(SQL As String) As ADODB.Recordset
Dim conn As New ADODB.Connection
conn.Provider = "Microsoft.JEt.Oledb.4.0"
conn.ConnectionString = App.Path + "\Database\jams.mdb"
conn.Open
Set MySQL = New ADODB.Recordset
MySQL.LockType = adLockOptimistic
MySQL.CursorType = adOpenKeyset
MySQL.Open SQL, conn
End Function




No comments:

Post a Comment