Hi, I’ve been trolling these forums for a while now, and while I’ve found other related threads (e.g., http://bytes.com/topic/access/answer...using-code-sql), nothing has addressed my problem, so I’m going to have to post. :)
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 ActivityDescrip tion
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:
frmGoalsAndObje ctives (set to default view = single):
Record Source is a SQL query on the above tables; this is a simplified rendering of it:
(I know this works for everything else in the database: reports, forms, etc)
subForm (set to default view = continuous forms):
subfrmActivitie s (linked Master/Child via PID, GNum, ONum)
Record Source is:
(I know this works everywhere else in my database, reports, etc)
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 frmGoalsAndObje ctives 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 ActivityDescrip tions (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 (qryFilterActivi ties) 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.)
However, when in the VBA code for the filter button, I try
, it pops up a request for tblActivities.[Activity Description] in addition to the “Text to Find in Activities”.
When I try
I get the same thing.
When I set the text for the query into “strFilter” and try
it fails on a syntax error (3075) in query expression because it cuts the string off at 255 characters (the example SQL above has shorter names than some of the real tables and fields).
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
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 ActivityDescrip tion
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:
frmGoalsAndObje ctives (set to default view = single):
Record Source is a SQL query on the above tables; this is a simplified rendering of it:
Code:
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):
subfrmActivitie s (linked Master/Child via PID, GNum, ONum)
Record Source is:
Code:
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 frmGoalsAndObje ctives 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 ActivityDescrip tions (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 (qryFilterActivi ties) 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.)
Code:
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?] & "*"));
Code:
DoCmd.OpenForm “frmGoalsAndObjectives”, , “qryFilterActivities”
When I try
Code:
DoCmd.ApplyFilter “qryFilterActivities”
When I set the text for the query into “strFilter” and try
Code:
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
Comment