filter a subform on loading main form

s_samira_21

Registered User.
Local time
Today, 22:36
Joined
Jun 8, 2011
Messages
52
Hi again

I Have a split form named Organization_List that when I click on each record another form named Organization_Details opens that shows that records details. Organization_Details contains 3 tabs.
In each tab I have one Subform that I want to be filtered based on the ID_ text box on main form (Organization_Details) named txt_ID.
for example tab projects contains project subform that shows all projects list. I want that when Organization_Details opens for Organization that its ID is 10, my subform filter for projects that are related with this organization.

for this I used this code on Organization_Details form load event:

Private Sub Form_Load()

Dim OrgID As Integer
OrgID = Me.txt_ID.Value
Form_Project_subform.Filter = "ID_ = OrgID"
Form_Task_subform.FilterOn = True

End Sub

but when the Organization_Details is loaded, a message box is shown that says: "enter parameter value" OrgID

What is the problem and what can I do?
 
The line

Form_Project_subform.Filter = "ID_ = OrgID"

Should be

Form_Project_subform.Filter = "ID_ = " & OrgID
 
Three other points to bear in mind:

You can refer to a form in a subform by using the name of the subform control (not the name of the form), which helps if the name of the form changes. Let's say you called the subform control subProject then the line would be:

subProject.Form.Filter = "ID_ = " & OrgID

Secondly, you probably should be checking for a null txt_ID.Value

Code:
Private Sub Form_Load()
    With subProject.Form
        .Filter = "ID_ = " & Nz(txt_ID.Value,0)
        .FilterOn = True
     End With
End Sub

However, you may be replicating a feature access provides for you already:
Can't you just set the subform's master/child properties to do this?
If txt_ID is bound to a field then set the Link Master Field property of each subfom to that field and the Link Child Field property to the appropriate field of the subform
 
Last edited:
ok the message box doesn't shown any more but no filter occurs the subform is empty and doesn't show the list
 
Then I suspect you're filtering on the wrong field.

The ID_ field of the project

Wouldn't there be an Organisation_ID_ field (I'm guessing the name) that relates the Project table to the Organisation table (shows which organisation a project belongs to)? That would be the field to filter on.
 
wow wow
I did it, I did it,
Thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
:-*
 

Users who are viewing this thread

Back
Top Bottom