Solved Using either Global Variable or Form field as query criteria (1 Viewer)

ebs17

Well-known member
Local time
Today, 14:45
Joined
Feb 7, 2020
Messages
1,946
Would WHERE FieldA IN (SELECT Param FROM ParameterTable) work if I could put the values from the listbox into a table?
Naturally. Just remember to clean up any legacy issues in the table beforehand.
If such a parameter table is used excessively, there is also the possibility that the database will be bloated => outsourcing of the real table to a temporary local backend.
 

GinnyR

New member
Local time
Today, 13:45
Joined
Apr 27, 2023
Messages
24
Are you using a list box with multiple selections in the form for a selection? This can only be evaluated using VBA. How accurate is your evaluation?

There are several ways to use a multiple selection in a filter, for example ...
SQL:
WHERE FieldA IN ("A", "C", "E")

WHERE Instr(1, "|A|C|E|", "|" & FieldA & "|") > 0

WHERE FieldA IN (SELECT Param FROM ParameterTable)

It is certainly understandable that you have to formulate your selection in such a way that it can be used and function in the selected filter variant.
With an existing string array, variant 2 could be used.
Code:
Public Function MyChoice() As String
     MyChoice = "|" & Join(YourStringArray, "|") & "|"
End function

'------------------------------------------------

WHERE Instr(1, MyChoice(), "|" & FieldA & "|") > 0

In serious database environments, value will be placed on performance, even with larger amounts of data, and it is essential to enable index use there. These now offer variants 1 and 3, but not variant 2.

Additional aspect: An OR link of the multiple selection was considered here. With an AND link, things get a little more complex.
The WHERE FieldA IN (SELECT Param FROM ParameterTable)[/CODE] was the most efficient and simplest solution to what I needed. I make a table from the ListBox.ItemsSelected and use the table in the Query exactly as listed here. I delete the table after the query has run. Marvellous. Thanks so much for the help.
 

GinnyR

New member
Local time
Today, 13:45
Joined
Apr 27, 2023
Messages
24
Thanks to everyone for the help with this problem. I've learnt a lot. Appreciated.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:45
Joined
Sep 21, 2011
Messages
14,306
The WHERE FieldA IN (SELECT Param FROM ParameterTable)[/CODE] was the most efficient and simplest solution to what I needed. I make a table from the ListBox.ItemsSelected and use the table in the Query exactly as listed here. I delete the table after the query has run. Marvellous. Thanks so much for the help.
Might be better just to delete the records, else bloat will be more I believe?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:45
Joined
Feb 28, 2001
Messages
27,186
Might be better just to delete the records, else bloat will be more I believe?
Affirmative on Gasman's comment. Too many table add/delete operations will cause bloat. Actually, INSERT/DELETE operations will also cause some degree of bloat. However, if these people who go into the field were to make a new copy of the master FE for travel use with each visit and THEN reload what needed to be reloaded, you could put a blank table in the COPY as part of the "preparing to go on the trip" sequence. In which case the new copy would have minimum bloat and you would just discard the data with each new prep step. The table would be local to the FE and thus easily accessible.
 

GinnyR

New member
Local time
Today, 13:45
Joined
Apr 27, 2023
Messages
24
Affirmative on Gasman's comment. Too many table add/delete operations will cause bloat. Actually, INSERT/DELETE operations will also cause some degree of bloat. However, if these people who go into the field were to make a new copy of the master FE for travel use with each visit and THEN reload what needed to be reloaded, you could put a blank table in the COPY as part of the "preparing to go on the trip" sequence. In which case the new copy would have minimum bloat and you would just discard the data with each new prep step. The table would be local to the FE and thus easily accessible.
That will be a future feature. Hopefully I won't be involved then. I'm supposed to be retired!!

Thanks :cool:
Ginny
 

Users who are viewing this thread

Top Bottom