Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select Case statement (2002)

    On my form I have a combo box containing the following values: PL, B, I, A, M1, M2, MO, and E

    If a user selects PL or B or I or A the value of a field named LEP should update to 1

    If they select M1 the field LEP should update to 2

    If they select M2 the field LEP should update to 3

    If they select MO the field LEP should update to 4

    If they select E the field LEP should update to null

    In the after update for the combo box I was able to accomplish what I wanted with a series of IF statements but I am sure the code would be much cleaner with a select case statement but I can't seem to figure out how to create it.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  2. #2
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select Case statement (2002)

    I worked it out a different way that will be much shorter than using select case. I added another column to my combo box containing the value I wanted in the LEP field and set the column width to 0. In the after update for my combo box I only needed one statement: Me.LEP = cmbLevel.Column(1)
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Select Case statement (2002)

    Oops, I see that you found a better solution. Well, perhaps somebody else can use this reply to see how a Select Case statement works.

    Try something like this, where ComboName should be replaced with the name of your combo box.

    Private Sub ComboName_AfterUpdate()
    Select Case Me.ComboName
    Case "PL", "B", "I", "A"
    Me.LEP = 1
    Case "M1"
    Me.LEP = 2
    Case "M2"
    Me.LEP = 3
    Case "MO"
    Me.LEP = 4
    Case "E"
    Me.LEP = Null
    End Select
    End Sub

  4. #4
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select Case statement (2002)

    I appreciate your showing me the correct way to write the select case statement because reading your code showed me what I was doing wrong and will help me with the next select statement I need to write.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •