Unable to filter subform

S

Suzie Raboin

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
 
A

Allen Browne

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 & """"
 
S

Suzie Raboin

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
 

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