1

オプション グループ コード (このような) をより効率的に記述する方法はありますか?

Select Case frmCity.Value
        Case 1
            Me.frmCustomersSub.Form.Filter = "City = 'Brazil'"
            Me.frmCustomersSub.Form.FilterOn = True
        Case 2
            Me.frmCustomersSub.Form.Filter = "City = 'France'"
            Me.frmCustomersSub.Form.FilterOn = True
        Case 3
            Me.frmCustomersSub.Form.Filter = "City = 'Mexico'"
            Me.frmCustomersSub.Form.FilterOn = True
        Case 4
            Me.frmCustomersSub.Form.Filter = "City = 'UK'"
            Me.frmCustomersSub.Form.FilterOn = True
 End Select
4

1 に答える 1

2

選択機能は次のことに役立ちます。

Dim cityName As String

If frmCity.Value > 0 And frmCity.Value <= 4 Then
    cityName = Choose(frmCity.Value, "Brazil", "France", "Mexico", "UK")

    Me.frmCustomersSub.Form.Filter = "City = '" & cityName & "'"
    Me.frmCustomersSub.Form.FilterOn = True
End If
于 2013-06-26T12:57:58.923 に答える