How To Make A MS Access Login Form

Watch and find out how to make a MS Access login form. Login forms are useful to collect needed information from the user. In this video, you will find out how to make one with MS Access VBA.

[sourcecode language=”vb”]
Option Compare Database

‘=================
‘frmMainForm code:
‘=================

Private Sub Form_Close()

DoCmd.Close acForm, "frmLogin"

End Sub

Private Sub Form_Open(Cancel As Integer)

DoCmd.OpenForm "frmLogin", , , , , acDialog

End Sub

[/sourcecode]

[sourcecode language=”vb”]

Option Compare Database

‘=================
‘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)

strSQL = "SELECT UserName FROM tblUsers WHERE UserName=’" & strUser & "’"

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()

Dim strNewUser As String
Dim strSQLInsert As String

strNewUser = InputBox("Enter your name to register.")

strSQLInsert = "INSERT INTO tblUsers (Username) VALUES (‘" & strNewUser & "’)"

CurrentDb.Execute strSQLInsert

MsgBox "Great! Now enter ‘" & strNewUser & "’ in the user name box above."

End Sub

[/sourcecode]

You can download the database file, by clicking here.




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

MS Access SQL

Next Post

How To Make An Access Timer