Thanks for your reply Allen
This is another lengthy explanation hope you get through it all.
Debuging code, I do not know how to get the debugging to run unless I
try the filter and the error occurs. With the full code posted last
time with the bits from your web page I was unable to do this as the
pop up box comes up instead. So I went back to the original code:
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
'MsgBox (Form_EssentialOilname.doFilter.Value)
' MsgBox ("Record source: " & Form_EssentialOilname.RecordSource)
If Form_EssentialOilname.doFilter.Value = True Then
strSQL = "SELECT * FROM [Essential Oil name] RIGHT JOIN Scents ON
[Essential Oil name].[Essential oil name] = Scents.[Essential Oil]
WHERE "
strFilterSub = Me.Filter
strFilterEssentialOilname = Form_EssentialOilname.Filter
If (strFilterSub <> "" And strFilterEssentialOilname <> "") Then
strSQL = strSQL & " WHERE "
End If
If strFilterSub = "" Then
strSQL = strSQL & strFilterEssentialOilname
ElseIf strFilterEssentialOilname = "" Then
strSQL = strSQL & strFilterSub
Else
strSQL = strSQL & "(" & strFilterEssentialOilname & " AND " &
strFilterSub & ")"
End If
' MsgBox (strSQL)
Form_EssentialOilname.RecordSource = strSQL
Form_EssentialOilname.doFilter = False
End If
End Sub
Noting that this error only occurs when more than one sub form has
this code in it.
This code was put into the subform Scents and subform botanical name.
(I originally thought that the order I added the code in may be linked
to the problems but it doesn't matter if I put it in scents or
botanical first I still get the same problems)
- When I filter the Scents subform it works fine. ie subform and main
form are filtered, filter button on the tool bar is depressed, toggle
button is not depressed.
- When I filter the Botanical name subform it comes up with the error
(3145, syntax error in the WHERE clause)
If I try to debug I notice that the problem is not in the Botanical
name coding area but in the Scents coding area. Thus it looks as if it
is trying to go through this one first????
It highlights this bit yellow (4th line before the End Sub)
Form_EssentialOilname.RecordSource = strSQL
If I hold the curser over it a box comes up, usually both sides of the
= sign have the same thing. In this case they do not.
Form_EssentialOilname.RecordSource comes up with
Form_EssentialOilname.RecordSource = "Essential oil name"
and
strSQL comes up with
strSQL = "SELECT * FROM [Essential Oil name] RIGHT JOIN Scents ON
[Essential Oil name].[Essential oil name] = Scents.[Essential Oil]
WHERE "
I stop the debug and I go back into the form, the filter has been
applied to the subform but not the main form. Both the filter button
and the toggle button are depressed (1), 2) and 3) are tried from this
point ie when both the filter button and toggle button are depressed)
1) I click on the filter button on the tool bar to turn it off the
same error occurs. I go debug and press stop, and go back to the form,
the filter is applied to the main form but no longer to the subform
and both buttons are not depressed any more.
OR
2) If I press the arrows down the bottom of the main form to go to the
next form the filter applies to the main form without an error and the
toggle button is no longer depressed. If I click on the depressed
filter button on the tool bar the subform filter clears and the main
form is still filter (as I expect it to be).
3) If I press the toggle button, it is released. The filter button is
still depressed, if I press it, it is released and the filter in the
subform is unfiltered. None of this effects the main form.
More info. If I filter (toggle button) in the Scents subform, and with
out unfiltering (clicking on the depressed filter button on the tool
bar) I filter (toggle button) in the Botanical Name subform it works.
Scenario 2, with 3 subforms. Code added to Scents, Botanical Name and
Made from subforms.
-If I filter with toggle in Made from it works. ie subform and main
form are filtered, filter button on the tool bar is depressed, toggle
button is not depressed.
-If I filter in Scents it comes up with the error (3145) in the Made
from coding area
with this bit highlighted
Form_EssentialOilname.RecordSource = strSQL
when I put curser over it it shows that
Form_EssentialOilname.RecordSource = "Essential oil name"
strSQL = "SELECT * FROM [Essential Oil name] RIGHT JOIN [Made from] ON
[Essential Oil name].[Essential oil name] = [Made from].[essential
oil] WHERE "
I stop the debug and I go back into the form, the filter has been
applied to the subform but not the main form. Both the filter button
and the toggle button are depressed (1), 2) and 3) are tried from this
point ie when both the filter button and toggle button are depressed)
1) I click on the filter button on the tool bar to turn it off the
same error occurs. I go debug and press stop, and go back to the form,
the filter is now applied to the main form but no longer to the
subform. Both buttons are no longer depressed.
OR
2) If I press the arrows down the bottom of the main form to go to the
next form the error (3145) occurs this time in the Botanical Name
coding area
with this bit highlighted
Form_EssentialOilname.RecordSource = strSQL
when I put curser over it it shows that
Form_EssentialOilname.RecordSource = "Essential oil name"
strSQL = "SELECT * FROM [Essential Oil name] RIGHT JOIN [Botanical
Name] ON [Essential Oil name].[Essential oil name] = [Botanical
Name].[Essential Oil] WHERE "
If I stop debug and go back to the form the toggle button is no longer
depressed. And the filter is applied to both the subform and the main
form. If I click on the depressed filter button on the tool bar the
subform filter clears and the main form is still filter (as I expect
it to be).
3) If I press the toggle button, it is released. The filter button is
still depressed, if I press it, it is released and the filter in the
subform is unfiltered. None of this effects the main form.
- If I filter in the Botanical Name subform it comes up with the error
in the Made from coding area
with this bit highlighted
Form_EssentialOilname.RecordSource = strSQL
when I put curser over it it shows that
Form_EssentialOilname.RecordSource = "Essential oil name"
strSQL = "SELECT * FROM [Essential Oil name] RIGHT JOIN [Made from] ON
[Essential Oil name].[Essential oil name] = [Made from].[essential
oil] WHERE "
If I stop debug and go back to the form the filter is applied to the
subform but not the main form.Both the filter button and the toggle
button are depressed (1), 2) and 3) are tried from this point ie when
both the filter button and toggle button are depressed)
1) If I click on the filter button on the tool bar to turn it off the
same error occurs in the Made from coding area . If I click debug and
then stop another error occurs this time in the Scents coding area
(same error just the strSQL = the scents strSQL) If I go back to the
form, the filter is now applied to the main form but no longer to the
subform. Both buttons are no longer depressed.
OR
2) If I press the arrows down the bottom of the main form to go to the
next form the filter applies to the main form without an error and the
toggle button is no longer depressed. If I click on the depressed
filter button on the tool bar the subform filter clears and the main
form is still filtered (as I expect it to be).
OR
3) If I press the toggle button, it is released. The filter button is
still depressed, if I press it, it is released and the filter in the
subform is unfiltered. None of this effects the main form.
It doesn't seem to matter which code is added first but there does
seem to be an order to it as the same errors occur in each subform no
matter which one is entered in first, maybe has to do with which
subform was entered first into the form - I will try this next but I
have spent hours compiling this so I am off to bed.
Hope you got through it all, I tried to make it flow as easy as I
could but there does seem to be a trend.
Kathryn
Allen Browne said:
Replies embedded.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
"Kathryn Fletcher" <
[email protected]> replied in message
[snip]
2)Found an event procedure posted in another message and played around
with it using some code from Allen Browne at
http://users.bigpond.net.au/abrowne1/ser-28.html
That site has actually moved to:
http://allenbrowne.com/ser-28.html
It is not supposed to be on the bigpond server any longer. (Looks like they
can't even get that right.)
Problem 2 - unsolved
I have copied and pasted the OnApplyFilter code into other subforms,
changing the strSQL using the query method.
The problem comes when I try and filter in the additional subforms.
Sometimes??? (Don't understand why only sometimes)a pop up comes up
with the error message 3145 Syntax error in WHERE Clause. If I press
okay the filter still works and you can carry on like normal. You can
filter as many times as you want in the same subform or in any of the
other subforms containing the code (again sometimes the error coming
up) but the code still works. I have no idea what the sytax error is
as I did not write the code I just adjusted it to suit my purposes.
Can some one please help me, I have nearly finished what I wanted to
achieve after many hours of work. I have learnt a fair bit but still
don't fully understand the stuff enough to know what is wrong with my
WHERE clause.
There are many possible valid reasons for this error, such as wrong or
missing delimiter, incorrect brackets, misunderstanding the field name or
parameter, misunderstanding which field is being referenced (e.g. where a
primary table and related table have fields with the same name.), or even
things like the wrong thing having focus.
When you receive the error message, the dialog has Debug and End buttons? If
so, choose Debug, and print the string you are trying to use as a filter.
Then try to create a query using that as the WHERE clause, and see if you
can identify what the problem is.
It is also possible that the message indicates some kind of corruption.