Filtering by a combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I have two combo boxes on a form with which I want to choose a value which
will then filter the form by this value.

One of the combo boxes,
Services works fine with the following code...

Private Sub Combo48_AfterUpdate()
Me.Filter = "[Service] = '" & Combo48 & "'"
Me.FilterOn = True
End Sub

But my other one won't work, I have used the same code with alterations for
appropriate names etc;

Private Sub Combo88_AfterUpdate()
Me.Filter = "[FleetNo] = '" & Combo88 & "'"
Me.FilterOn = True
End Sub

When I attempt to run this filter I get the following error message...

Run-time error '2001':
You cancelled the previous operation.

When it then goes to debug my code the Me.FilterOn = True is highlighted
showing
Me.FilterOn = True when mouse is over Me.FilterOn and True = True when over
the word true.

I'm totally stumped as to why it is erroring on one and not the other.

If you have any ideas why or ways to resolve this it would be greatly
appreciated.

Thanks

Steve A
 
If FleetNo is a Number field (not a Text field), lose the extra quotes,
i.e.:
Me.Filter = "[FleetNo] = " & Combo88
 
Thats great Allen,
Thanks

Allen Browne said:
If FleetNo is a Number field (not a Text field), lose the extra quotes,
i.e.:
Me.Filter = "[FleetNo] = " & Combo88

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Steve A said:
Hi
I have two combo boxes on a form with which I want to choose a value which
will then filter the form by this value.

One of the combo boxes,
Services works fine with the following code...

Private Sub Combo48_AfterUpdate()
Me.Filter = "[Service] = '" & Combo48 & "'"
Me.FilterOn = True
End Sub

But my other one won't work, I have used the same code with alterations
for
appropriate names etc;

Private Sub Combo88_AfterUpdate()
Me.Filter = "[FleetNo] = '" & Combo88 & "'"
Me.FilterOn = True
End Sub

When I attempt to run this filter I get the following error message...

Run-time error '2001':
You cancelled the previous operation.

When it then goes to debug my code the Me.FilterOn = True is highlighted
showing
Me.FilterOn = True when mouse is over Me.FilterOn and True = True when
over
the word true.

I'm totally stumped as to why it is erroring on one and not the other.

If you have any ideas why or ways to resolve this it would be greatly
appreciated.

Thanks

Steve A
 
Back
Top