Filter Subform results based on Main form unbound field

Arvin

I'm liv'in the dream ....
Local time
Yesterday, 21:52
Joined
Jul 22, 2008
Messages
192
Hello,

I am trying to filter a sub form based on a unbound field value on the main form but have had no success.

I have tried numerous things such as vb code, and query filters but no luck ....

what would be the best approach?

Thank you in advance,
 
You could do this in VBA. (assuming the unbound control is a string.

Code:
Forms!mainformname!subformname.Form.filter = '"&Forms!mainformname.controlname&"'

The subform name needs to be the sub form container and not the actual form.

If the control is an integer or date then change the syntax to suit.

This should work ok.
 
Thank you for the response ...

Quick ... and probably a stupid question ..but .. I would put/apply the code above on the main form ...yes?

like a on load event ?
 
Thanks for putting my posting right Bob. Must learn to read what I write before submitting!! :mad:
 
Hello,

1st ..thank you for the replies ...

i have tried all of the suggestions but none have worked ... I have attached the DB ...

Thank you in advance....
 

Attachments

Which form - which controls?

Sorry ...

Subform is called "EmployeeDashboardSubfrm" and the control is called "Weekending"

It is located at the top/middle is the Mainfrm ....
 
I've been looking and it would appear that you have a couple of problems -

The code should be:
Code:
Private Sub Form_Load()
Me.EmployeeDashboardSubfrm.Form.Filter = "[WeekEnding]= #" & DateValue(Me.CurRptWeekendDatetxt) & "#"
Me.EmployeeDashboardSubfrm.Form.FilterOn = True
End Sub

because you are working with dates and you shouldn't have CurrentDate using =NOW() but use =Date() instead.
 
Hi Bob,

Thank you for your response, I have change the CurrentDate to =Date() instead of =Now() and have applied the vb code above to the Mainfrm load event .. but the subform is blank ...
 
I'm uploading the revised version. You may also need to do what I did and go use some formatting and DateValue in the query.
 

Attachments

Hello,

I am trying to filter a sub form based on a unbound field value on the main form but have had no success.

I have tried numerous things such as vb code, and query filters but no luck ....

what would be the best approach?

Thank you in advance,

Here's a snippet from a program I use that changes the subform based on the unbound field selection in the main form.

SELECT tbl2010_Data.*
FROM tbl2010_Data
WHERE (([Date_recvd]=Forms!frmSearch!txtDate_Recvd Or forms!frmSearch!txtDate_Recvd Is Null)=True)

ORDER BY [Date_recvd];
 
I'm uploading the revised version. You may also need to do what I did and go use some formatting and DateValue in the query.

Hi Bob,

Thank you so much! ... I did exactly as you stated and it works!

Thank you again
 
Hello to all of you,

I have a main form (start_protocol) with an unbound subform (placeholderform).

Using a button in mainform I open a search form (search_protocol) inside the unbound form, by the code:
-------------------------------------------------------------------
[placeholderform1].Visible = False
[placeholderform].Visible = True
Me.placeholderform.SourceObject = "SEARCH_PROTOCOL"
--------------------------------------------------------------------
The search form (has a run query button) is build from a query named: search_protocol.

I want to be able, as soon as I pass the button, to have the results (from the query) inside the unbound subform, of the main form (Start_protocol).

How can I do this?


Please Help!!!
 

Users who are viewing this thread

Back
Top Bottom