Re: Filter Parent Form by Subform's Listbox Selection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mar 23, 10:37 pm, "kingston via AccessMonster.com" <u27511@uwe>
wrote:
Use the ListBox's AfterUpdate event to create a criteria string (a WHERE
clause without the WHERE). Then set the MainForm's filter and apply it:

Me.Parent.Form.Filter = "[Field123]='" & Me.Listbox & "'"
Me.Parent.Form.FilterOn = True





CC wrote:
Hi, I'm at my wits end with this. Could someone please help out?

I have a MainForm which contains a SubForm. The SubForm contains a
Listbox (single select, not multiselect).
I can return the value selected in the SubForm Event OnClick.
The MainForm is bound to a table as it's RecordSource.

I would like to take the value selected in the listbox on the SubForm
and use it to filter the results
on the MainForm.

My Current SubForm Event OnClick Code:
Private Sub StuffList_Click()
Forms![FM_TB_MainForm]!TestStuff = Me.StuffList 'Returns
selected item to TextBox on MainForm.
Forms![FM_TB_MainForm].Form.Filter = "((TB_Table.[Part-No]= " &
me.StuffList & "))"
Forms![FM_TB_MainForm].Form.FilterOn = True
End Sub

Running this code I get a 'Run-Time Error '2465': Microsoft Access
can't find the field 'Forms' referred to in your expression'.

Sorry if there is some obvious solution. Could you please help.
Pulling out all my last remaining hairs. o_O

--
Message posted viahttp://www.accessmonster.com- Hide quoted text -

- Show quoted text -

Actually, I found the problem. I wasn't putting the " ' " around the
listbox in the above statement.

So my statement should be:
Forms![FM_TB_MainForm].Form.Filter = "((TB_Table.[Part-No]= '" &
me.StuffList & "'))"

.



Relevant Pages

  • Re: Populate ListBox from filtered list
    ... 'and use it to populate a 2 column listbox ... > list (Auto Filter, 2 columns) but it fails if there is a filter in place ... > Private Sub UserForm_Initialize ...
    (microsoft.public.excel.programming)
  • SYNC Form to listbox
    ... I have a listbox which can display all records or provide a limited ... except in the one situation where the listbox filter is changed. ... first click correctly updates the listbox, ... Private Sub Frame33_Click ...
    (comp.databases.ms-access)
  • Re: List box question
    ... > Private Sub SelectorListBox_AfterUpdate ... > another record in the form, the highlited 'selected item' in the listbox ... > I have the form following the selection in the listbox but I need the ... >> You could use the Form Filter property to filter for a specific record. ...
    (microsoft.public.access.forms)
  • Re: Filter Parent Form by Subforms Listbox Selection
    ... Then set the MainForm's filter and apply it: ... I can return the value selected in the SubForm Event OnClick. ... The MainForm is bound to a table as it's RecordSource. ... Private Sub StuffList_Click ...
    (microsoft.public.access.forms)
  • Re: Filter Table / List Box
    ... If the Listbox is from the Control toolbox, ... Private Sub ListBox1_Click ... > I have a list Box at present with relivant options, ... > option i want to make an amendment to the filter..? ...
    (microsoft.public.excel.misc)