Previous  Home  Next

Forms

This is the code from the introduction to Forms (mod03Forms)

Option Explicit
Public strText As String
Public strOption As String

Sub Forms_1()
    ' Creating/Showing/Unloading a form

    ' Forms are a more sophisticated way of getting user input than
    ' simple InputBox commands

    ' For example:
    frmMyForm1.Show

    ' now the user has dismissed the form
    ' let's see what they entered

    Debug.Print frmMyForm1.TextBox1.Text

    If frmMyForm1.OptionButton1.Value = True Then
        Debug.Print "Yes"
    End If
    If frmMyForm1.OptionButton2.Value = True Then
        Debug.Print "Chocolate"
    End If
    If frmMyForm1.OptionButton3.Value = True Then
        Debug.Print "Teal"
    End If

    ' we're done with the form so unload it
    Unload frmMyForm1

    ' But what if we want to make the form data available until much later?
    ' And wouldn't it make more sense to keep all the form's logic
    ' in the form itself?

End Sub

Sub Forms_2()
    ' This uses a form with the logic built in
    ' Note that we had to declare a few PUBLIC variables
    ' so the form could get at them

    frmMyForm2.Show

    ' we're done with the form so unload it
    Unload frmMyForm2

    ' let's see what they entered - our variables still have the values
    ' the form code assigned them:
    Debug.Print strText
    Debug.Print strOption

    ' CODE RE-USE
    ' We can export the form to a file and import it into other projects

End Sub

Click Next to continue

Previous  Home  Next