Skip to main content

Access 2013 VBA How to write your first Hello World program using DLookup function

Microsoft Access 2013 VBA Programming - How to write your first Hello World program using DLookup function.

👨‍💻 Here is my online course: Visual Basic .NET (VB.NET), Access Database and Crystal Reports Course.
🎯 Enroll now (Full lifetime access): http://bit.ly/2YRy99d

📌 Related Videos (YouTube Playlist): Microsoft Access VBA Programming (Visual Basic for Applications).
📺 http://bit.ly/3cOWJ1g

▶️ Subscribe and hit the bell to see new videos: http://bit.ly/2zAg8Ag


#BEGIN

'- Form 1

Option Compare Database

Private Sub VBA_Button_Click()
     MsgBox "Hello World!", vbInformation, "This is my first VBA - Hello World!"
End Sub

'- Form 2

Option Compare Database

Private Sub btnHello_Click()

On Error GoTo Hello_Err

If IsNull(cboGreetings) Then

    Exit Sub

Else

    If IsNull(txtPassword) Or (txtPassword.Value = "") Then

        Me.txtPassword.Value = "Please enter your password!"
        txtPassword.ForeColor = vbRed
        txtPassword.BackColor = vbWhite
        btnHello.Enabled = False

    Else

        Dim varGreeting As Variant
        Dim strPos As String

        If Me.txtPassword.Value = _

             DLookup("Password", "[Hello World Table]", _
                  "Greetings= '" & Me.cboGreetings.Value & "'") Then

            varGreeting = Me.cboGreetings.Value

            txtPassword.ForeColor = vbWhite
            txtPassword.BackColor = vbBlue

            strPos = DLookup("Position", "[Hello World Table]", _
            "Greetings= '" & Me.cboGreetings.Value & "'")

            MsgBox varGreeting & "," & vbCrLf & vbCrLf & _
                           "and i am a " & strPos, vbInformation, "Congrats! Password is correct!"

        Else

            Call Wrong_Password

            MsgBox "The password you entered is incorrect", vbCritical, "Sorry! Invalid Password"

        End If

    End If

End If

Hello_Err_Exit:
            Exit Sub

Hello_Err:
            MsgBox "Error Number is " & Err.Number & vbCrLf & vbCrLf & _
            "Error Description: " & Err.Description, vbCritical, "Say Hello Error!"
            Resume Hello_Err_Exit                   

End Sub

Private Sub cboGreetings_AfterUpdate()
        txtPassword.SetFocus
End Sub

Private Sub Form_Load()
On Error Resume Next

    With txtPassword
            .Value = ""
            .ForeColor = vbBlack
            .BackColor = vbWhite
            .SetFocus
    End With

End Sub

Private Sub txtPassword_Click()
    Call Form_Load
    btnHello.Enabled = True
End Sub

Private Sub Wrong_Password()

    With txtPassword
            .ForeColor = vbWhite
            .BackColor = vbRed
    End With

    btnHello.Enabled = False

End Sub

#END

Follow me around
✔ Want to get updates on new courses or other cool free stuff? Just follow me on social media if that's your thing!

📺 Pages:
📍 https://www.facebook.com/CodeAMinute
📍 https://www.facebook.com/IbasskungTutorial
📍 https://www.facebook.com/codewithibasskung

📺 YouTube:
📍 https://www.youtube.com/c/iBasskung

📺 Udemy (Online Course):
📍 https://www.udemy.com/vbnet-crystal-reports

📺 Twitter:
📍 https://twitter.com/#!/IBasskung

📺 Blogger:
📍 .NET: https://codeaminute.blogspot.com
📍 JAVA: https://javacodeminutes.blogspot.com
📍 VBA: https://vbacodeminutes.blogspot.com

💯 THANK YOU SO MUCH! 💯

#CodeAMinute #iBasskungTutorial #iBassskung #YouTube #AccessVBA #VBAProgramming

Comments