If Then Else code

lmcc007

Registered User.
Local time
Today, 14:30
Joined
Nov 10, 2007
Messages
635
Is there a cleaner or shorter way of writing the below code?

Code:
    If Me.NewRecord Then
        Me.cmdDetails.Visible = False
    Else
        If Me.cboActivity = 3 Or Me.cboActivity = 12 Or Me.cboActivity = 13 Or Me.cboActivity = 16 Or _
            Me.cboActivity = 17 Or Me.cboActivity = 18 Or Me.cboActivity = 19 Or Me.cboActivity = 20 Or _
            Me.cboActivity = 22 Or Me.cboActivity = 24 Or Me.cboActivity = 25 Or Me.cboActivity = 27 Or _
            Me.cboActivity = 28 Or Me.cboActivity = 31 Or Me.cboActivity = 32 Then
            Me.cmdDetails.Visible = False
        End If
    End If
 
Code:
If Me.NewRecord Then
    Me.cmdDetails.Visible = False
Else
    Select Case Me.cboActivity
        Case 3, 12, 13, 16, 17, 18, 19, 20, 22, 24, 25, 27, 28, 31, 32
            Me.cmdDetails.Visible = False
    End Select
End If
 
Code:
If Me.NewRecord Then
    Me.cmdDetails.Visible = False
Else
    Select Case Me.cboActivity
        Case 3, 12, 13, 16, 17, 18, 19, 20, 22, 24, 25, 27, 28, 31, 32
            Me.cmdDetails.Visible = False
    End Select
End If

Wow, looks 90% better. I was thinking select case but I thought I would have to do a Case for each record.

Thanks a bunch!
 

Users who are viewing this thread

Back
Top Bottom