How to write your first VBA Program in Access - Hello World!


How to write your first VBA Program in Access - Hello World!

🎓 Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS).
ðŸ“ē Enroll Now: https://bit.ly/2WcbRhX


'- 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

My Twitter

My Facebook

My Google+

My YouTube Channel

Thank you very much.
āļ‚āļ­āļšāļ„ุāļ“āļ„āļĢัāļš.

Comments