I'm having trouble using the filter by form in a SQL query via VBA in Access 2013. I didn't create the Access forms but was commissioned to correct an issue. Also the client told me that it worked in the previous Office versions and that the Access-Database hasn't been changed in the past few years. So it seems, that Access 2013 does something differently. But I couldn't figure out what.
As you may understand below, the red highlighted button should un-/check all the yellow highlighted checkboxes. This works perfectly fine until I add a filter by form (red box at the bottom of image). Ironically I encountered this issue only by filtering the red underlined field Programm_IDFS. Filtering by other fields works fine.
This query should uncheck the checkboxes but it fails because the value of strFilter is:
((Lookup_Programm__IDFS.Name="ad1incl"))
This may work for filtering, but it doesn't work as SQL restriction.
UPDATE dbo_tbl_ThisForm
SET dbo_tbl_ThisForm.Checkbox = 0,
dbo_tbl_ThisForm.Statusoffen = '0'
WHERE dbo_tbl_ThisForm.Testfall_ID NOT IN
(SELECT dbo_tbl_Restrictions1.Testfall_ID
FROM dbo_tbl_Restrictions1
WHERE dbo_tbl_Restrictions1.Auftrags_ID = " & gsVariable5 & ")
AND dbo_tbl_ThisForm.Testfall_ID NOT IN
(SELECT dbo_tbl_Restrictions1.Testfall_ID
FROM dbo_tbl_Restrictions1
WHERE dbo_tbl_Restrictions1.Auftrags_ID IN
(SELECT Auftrag_ID
FROM dbo_tbl_Restrictions2
WHERE Auftragstyp = " & Me.kfAuftragstyp & "))
AND " & strFilter & "
This query should check all the checkboxes. It works because I hard-coded all the values (actually this is only necessary for strFilter).
UPDATE dbo_tbl_ThisForm
SET dbo_tbl_ThisForm.Checkbox = -1,
dbo_tbl_ThisForm.Statusoffen = '-1'
WHERE dbo_tbl_ThisForm.Testfall_ID NOT IN
(SELECT dbo_tbl_Restrictions1.Testfall_ID
FROM dbo_tbl_Restrictions1
WHERE dbo_tbl_Restrictions1.Auftrags_ID = 544)
AND dbo_tbl_ThisForm.Testfall_ID NOT IN
(SELECT dbo_tbl_Restrictions1.Testfall_ID
FROM dbo_tbl_Restrictions1
WHERE dbo_tbl_Restrictions1.Auftrags_ID IN
(SELECT Auftrag_ID
FROM dbo_tbl_Restrictions2
WHERE Auftragstyp = 9))
AND dbo_tbl_ThisForm.Programm_IDFS = 35
If you need more information feel free to ask.
Any help/suggestion is appreciated. Thanks in advance.
EDIT:
When running the query with strFilter=((Lookup_Programm__IDFS.Name="ad1incl")) I get the following error:
"Run-time error '3061'. Too few parameters. Expected 1."
I now just figured out, that the un-/checking also doesn't work for the field Funktion. This and the Programm_IDFS field are both foreign keys of data type int in the table dbo_tbl_ThisForm.
When filtering by the field Fachbereich it works to un-/check the checkboxes, since that field is of data type varchar, so strFilter is set to a valid value:
((dbo_tbl_ThisForm.Fachbereich="Steuern"))
Those foreign keys both link to separate tables. Now how can I solve this? Do I need to include those tables in my query? Can I change something on the form?
Thank You