Unable to filter subform

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

Guest

I have an unbound subform will not allow me apply a filter based on
information that the user has already entered. I get an error message that
states "You canceled the previous operation."

I am trying to filter based on the Primary Key (an id number). However if I
filter based on another part of the record (consultant name) it works fine.
Does anyone know what might be causing this problem?

My code to open and filter the form is:

Forms![Switchboard]![Subform].SourceObject = "Consultant_Info"
Forms![Switchboard]![Subform].Form.Filter = ("[Firm_ID]=" & "'" & gvarFirm &
"'")
Forms![Switchboard]![Subform].Form.FilterOn = True

Thanks,
Suzie
 
Presumably the subform is bound to some table? Otherwise you cannot filter
it.

The "canceled" message indicates that the filter string is mal-formed.

If Form_ID is a Number type field (not a Text type), drop the extra quotes:
If IsNumeric(gvarFirm) And Not IsEmpty(gvarFirm) Then
With Forms![Switchboard]![Subform].Form
.Filter = "Firm_ID = " & gvarFirm
.FilterOn = True
End With
End If

If it is a Text field, try:
.Filter = "Firm_ID = """ & gvarFirm & """"
 
That was it...my ID is a Number type field. Never try to program on a Friday!

Thanks!

Allen Browne said:
Presumably the subform is bound to some table? Otherwise you cannot filter
it.

The "canceled" message indicates that the filter string is mal-formed.

If Form_ID is a Number type field (not a Text type), drop the extra quotes:
If IsNumeric(gvarFirm) And Not IsEmpty(gvarFirm) Then
With Forms![Switchboard]![Subform].Form
.Filter = "Firm_ID = " & gvarFirm
.FilterOn = True
End With
End If

If it is a Text field, try:
.Filter = "Firm_ID = """ & gvarFirm & """"

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

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

Suzie Raboin said:
I have an unbound subform will not allow me apply a filter based on
information that the user has already entered. I get an error message
that
states "You canceled the previous operation."

I am trying to filter based on the Primary Key (an id number). However if
I
filter based on another part of the record (consultant name) it works
fine.
Does anyone know what might be causing this problem?

My code to open and filter the form is:

Forms![Switchboard]![Subform].SourceObject = "Consultant_Info"
Forms![Switchboard]![Subform].Form.Filter = ("[Firm_ID]=" & "'" & gvarFirm
&
"'")
Forms![Switchboard]![Subform].Form.FilterOn = True

Thanks,
Suzie
 
Back
Top