Need to replace If ElseIf statements by loop

  • Thread starter Thread starter Sean
  • Start date Start date
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
 
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

Similar Threads

shorter method than elseif 1
Elseif not working 6
if elseif help 16
Help simplifying If statement 3
change certain cell colours in VBA 2
If...ElseIf...Then Statement 3
If Statements 2
Dates swapping 3

Back
Top