I’m using Access 2007. I have a form with a sub-form. I want to filter for text in the subform and only display records in the main form that have subforms matching the filter text. I have read Allen Brown’s example (ser-28.html) and others, and maybe my problem is how long the filter can be in VBA: is there a 255 character limit? Because I’m getting errors saying the filter is not valid that have obviously cut the filter at 255 characters. If that is true, any suggestions on working around that?
Otherwise, here is my set up:
Tables:
tblProject, with AutoNumber PID (project ID), and other fields
tblGoal, with linked PID, and Number GNum (goal number – non-unique), and GoalText
tblObjective, with linked PID and GNum, and Number ONum (objective number – non-unique), and ObjText
tblActivity, with linked PID, GNum, and ONum, and AutoNumber AID (Activity ID) and Memo ActivityDescription
A Project will have up to five Goals (1, 2, 3, 4, 5). Each Goal will have up to five Objectives (1, 2, 3, 4, 5). Each Objective will have up to five Activities (un-numbered). So project P could look like this:
G1O1
Activity: did somethingA
Activity: did somethingB
Activity: did somethingC
Activity: did somethingD
G1O2
Activity: did somethingA
Activity: did somethingB
Activity: did somethingC
Etc.
Form:
frmGoalsAndObjectives (set to default view = single):
Record Source is a SQL query on the above tables; this is a simplified rendering of it:
Expand|Select|Wrap|Line Numbers
- SELECT tblProject.field1, tblProject.field2, tblGoal.GNum, tblGoal.GoalText, tblObjective.ONum, tblObjective.ObjText
- FROM (tblProject INNER JOIN tblGoal ON tblProject.PID = tblGoal.PID) INNER JOIN tblObjective ON (tblGoal.GNum = tblObjective.GNum) AND (tblGoal.PID = tblObjective.PID);
subForm (set to default view = continuous forms):
subfrmActivities (linked Master/Child via PID, GNum, ONum)
Record Source is:
Expand|Select|Wrap|Line Numbers
- SELECT tblActivity.ActivityDescription, tblActivity.PID, tblActivity.GNum, tblActivity.ONum
- FROM tblActivity;
The Form is set to display one Goal/Objective pair at a time (so with the above example there are 7 records in the form to click through; in reality, there are over 200 projects, which comes to about 1700 Goal/Obj pairs).
I have a text box and button (I’ve also tried it with a pop-up) on the frmGoalsAndObjectives to initiate a filter by calling a VBA sub. My goal is to only show the Goals and Objectives where the text matches in one (or more) of its ActivityDescriptions (e.g., “*ingD*” would mean only G1O1 would be in the filtered record list, after matching the fourth Activity – I’ll worry about only displaying the Activities that match later).
The following SQL worked in a test query (qryFilterActivities) to return the list of Goals and Objectives that contained Activities with the filter text. (It popped up “Text to Find in Activities?” to which I could enter “camp”; I verified by running a text filter on the Activity Description column in tblActivities that it returned the same list.)
Expand|Select|Wrap|Line Numbers
- SELECT tblObjectives.PID, tblObjectives.GNum, tblObjectives.ONum
- FROM tblObjectives INNER JOIN tblActivities
- ON ((tblObjectives.PID = tblActivities.PID) AND (tblObjectives.GNum = tblActivities.GNum) AND (tblObjectives.ONum = tblActivities.ONum))
- WHERE (tblActivities.[Activity Description] Like ("*" & [Text to Find in Activities?] & "*"));
Expand|Select|Wrap|Line Numbers
- DoCmd.OpenForm “frmGoalsAndObjectives”, , “qryFilterActivities”
When I try
Expand|Select|Wrap|Line Numbers
- DoCmd.ApplyFilter “qryFilterActivities”
When I set the text for the query into “strFilter” and try
Expand|Select|Wrap|Line Numbers
- Me.Filter = strFilter
- Me.FilterOn = True
So I think my questions are:
• Is there a limit to filter length at 255 characters?
• Which method (OpenForm, ApplyFilter, Me.Filter/FilterOn) should work, if I weren’t encountering the 255 limit?
• Is there a better way to do this? (I wasn’t sure if the other examples were the same or if the fact that they were fewer levels of tables made a difference.)
Sorry for the length of my post; after reading a lot of other posts, it was clear that the more detail and information early on, the easier it was to answer the questions in the specific case. Many thanks in advance.
kevin