Noah Xu
Noah Xu

Reputation: 167

The IF....then statement in Access VBA

I am testing my understanding on the if then statement, I wrote a little thing down below but when I hit run, nothing happened. I was expecting a msgbox will appear asking me if I want to quit or not and giving me choices to choose. Did I miss anything please. Thanks

Sub testifthenelse(bQuit As Boolean)
Dim s As String
s = "Do you want to quit?"
If MsgBox(s, vbYesNo, "Quite?") = vbYes Then
bQuit = True
Else
bQuit = False
End If
End Sub

Upvotes: 0

Views: 138

Answers (1)

user3598756
user3598756

Reputation: 29421

you must call it from another sub:

Sub main()
    Dim bQuit As Boolean

    testifthenelse bQuit
End Sub

while, if you want to run and test it "by itself" then make the argument optional

Sub testifthenelse(Optional bQuit As Variant)
    Dim s As String

    s = "Do you want to quit?"
    If MsgBox(s, vbYesNo, "Quite?") = vbYes Then
        bQuit = True
    Else
        bQuit = False
    End If
End Sub

Upvotes: 2

Related Questions