Here is a basic example of using a case statement. The basic elements to keep in mind are the following:
- Create a text box in an MS Access Form and name it “txtInput”
- Crete a button and name it “cmdExample1”
- Create another text box and name it “txtYouEntered”
- Within the properties of you Button you created, choose the Event “On click” and go into the VB code screen. Copy and paste the following.
Private Sub cmdExample1_Click() 'This is going to look at the value entered in the "txtInput" text box that we created on the form Select Case txtInput ' This is saying if the value in the above 'txtNumber" text box is equal to 1 then in the second text box print this "one" Case Is = 1 Me.txtYouEntered = "One" Case Is = 2 Me.txtYouEntered = "Two" Case Is = 3 Me.txtYouEntered = "Three" Case Is < 1 Me.txtYouEntered = "You entered a number less than 1" Case Is > = 4 Me.txtYouEntered = "You entered a number greater than 3" End Select End Sub
No related posts.