MS Access Select Case Example

Here is a basic example of using a case statement.  The basic elements to keep in mind are the following:

 

  1. Create a text box in an MS Access Form and name it “txtInput”
  2. Crete a button and name it “cmdExample1”
  3. Create another text box and name it “txtYouEntered”
  4. 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.

ms access select case example

 


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

Click here to download the example

No related posts.