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
'========================================================
'BY LOEBLCOM SERVICES 2013
'ERIK LOEBL(713)409-7041
'EMAIL: erik@loeblcomservices.com
'WEB:  http://loeblcomservices.com
'========================================================


'=================
'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
    Else
        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:
ms-access-login-form-rev.mdb




By the way, if you got or are getting value from the VBA information, please give me a tip, thanks!


These posts may help answer your question too...

How can I interact with other Office applications (Excel) using VBA in Access?

Need to write your Access data or query to an Excel file? Here is the how to do it: Most people are familiar with Excel and know how to use it well (enough), and when you start talking about Access, they get scared off, and don’t know what to do anymore. Well, here you are […]

How To Generate A XML File With Access VBA

XML is used to structure your data. You can send a CSV file to another person, but using XML, you can structure your data in a more elegant format, and get very specific about your fields, and what data is contained within your tags (your field names). This is different than a basic CSV file […]

Mouse Click Counter On Access Form

This post will demonstrate how you can count the number of clicks on your button in a certain time frame. It will function like a game . Here is the database form all in one: Option Compare Database Public m_dteStartTime As Date Public m_dteStopTime As Date Private Sub btnClicker_Click() Dim intValue As Integer Dim rst […]

Shared Access Database Management

Here is a handy setup for those who need to manage a shared access database. Either you can create this from scratch as per the example or add the new tables to your existing database. This setup will track: 1. the users currently using the database 2. what time the user and computer name currently […]

Previous Post

Access VBA Create Table

Next Post

Being More Specific In Access Import