MS Access Login Form Revised

MS Access Login Form Revised. Revised because I added some
stars to the password entry box, and a new registration form.

Make sure you set the InputMask property of the password textbox to “Password”!

Option Compare Database
'ERIK LOEBL(713)409-7041

'basUtilities code:

Public Function IsLoaded(ThisForm As String) As Boolean
    'is the form loaded or not
    If SysCmd(acSysCmdGetObjectState, acForm, ThisForm) <> 0 Then
        IsLoaded = True
        IsLoaded = False 'the form is closed
    End If
End Function

'frmLogin code:

Private Sub btnOK_Click()

    Dim strUser As String

    Dim strSQL As String
    Dim rst As Object
    Dim intCount As Integer
    strUser = Nz(Me.txtUser, 0)
    strPWD = Nz(Me.txtPassword, 0)

    strSQL = "SELECT user_name,user_pwd FROM tblUsers WHERE user_name='" & strUser & "' AND user_pwd= '" & strPWD & "'"
    Set rst = CurrentDb.OpenRecordset(strSQL)
    intCount = rst.RecordCount
    Select Case intCount
        Case 0
            MsgBox "incorrect credentials, try again"
        Case 1
            MsgBox "correct"
            Me.Visible = False
    End Select
End Sub

Private Sub lblRegister_Click()

    DoCmd.OpenForm "frmRegister"
    DoCmd.Close acForm, Me.Name
End Sub

'frmMainForm code:

Private Sub Form_Close()

    DoCmd.Close acForm, "frmLogin"

End Sub

Private Sub Form_Open(Cancel As Integer)

    DoCmd.OpenForm "frmLogin", , , , , acDialog
    If Not IsLoaded("frmLogin") Then
        Cancel = True
    End If
End Sub
'frmRegister code:

Private Sub btnOK_Click()

    Dim strNewUser As String
    Dim strPassword As String
    Dim strSQLInsert As String
    strNewUser = Me.txtUser
    strPassword = Me.txtPassword
    strSQLInsert = "INSERT INTO tblUsers (user_name,user_pwd) VALUES ('" & strNewUser & "','" & strPassword & "')"
    CurrentDb.Execute strSQLInsert
    MsgBox "Thanks for registering!"
    DoCmd.Close acForm, Me.Name
End Sub

Private Sub txtPassword_AfterUpdate()
     Me.lblPassword.Caption = Me.txtPassword
End Sub

Click here for the database and the code:

Offsite Related Information:

“Go Fund Me” Page

($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: ,