Need to replace If ElseIf statements by loop

S

Sean

I am using a list box to bring up any record on a form. The If ElseIf
statement is:
Private Sub List100_Click
If Me.List100.Value = 1 Then
DoCmd.ApplyFilter , "[ID] =1"
ElseIf Me.List100.Value = 2 Then
DoCmd.ApplyFilter , "[ID] =2"
ElseIf Me.List100.Value = 3Then
DoCmd.ApplyFilter , "[ID] =3"
etc.
End Sub

There is a limit to the number of records which may be checked.
As the code is repetitive I feel sure it can be looped but I do not know how.
Any help please?
JSFP
 
K

Ken Snell

Why not do it directly?

Private Sub List100_Click
If Len(Me.List100.Value & "") > 0 Then _
DoCmd.ApplyFilter , "[ID] =" & Me.List100.Value
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top