whitespace
Registered User.
- Local time
- Yesterday, 18:40
- Joined
- Aug 30, 2005
- Messages
- 51
Hello, I have a query that has a number of fields one of which is checking to see if one value is in a list. To do this I created the following function in vba..
and then in the query I simply use EnTot: tot([English Level])
I get the correct answer, the problem is this is unbelievably slow, so after help on this very forum I tried using SQL and thus in query designer I used:
This works miles faster and is perfect, however... Because there are a number of queries, databases and users that need to use this 'Tot' function/procedure it is impractical to have to change every query if I need to include "X" for example (as I would have to do if using the SQL version).
Is it possible to have a function in vba that somehow uses SQL to run as fast as the SQL version but obviously having the advantage of being a function that all the queries can use, instead of recreating it in every query. Does this make sense?
Any help is much appreciated.
Code:
Function tot(a As Variant) As Long
If a = "1" Or a = "2" Or a = "2A" Or a = "2B" Or a = "2C" Or a = "3" Or a = "4" Or a = "4+" Or a = "5" Or a = "6" Or a = "7" Or a = "D" Or a = "8" Or a = "E" Or a = "A" Or a = "B" Or a = "N" Or a = "W" Or a = "D" Or a = "T" Then tot = 1
End Function
and then in the query I simply use EnTot: tot([English Level])
I get the correct answer, the problem is this is unbelievably slow, so after help on this very forum I tried using SQL and thus in query designer I used:
Code:
EnTot: Sum(IIf([English Level] In ("1","2","3","4","5","6","7","8","E","A","B","N","W","D","T","Q"),1,0))
This works miles faster and is perfect, however... Because there are a number of queries, databases and users that need to use this 'Tot' function/procedure it is impractical to have to change every query if I need to include "X" for example (as I would have to do if using the SQL version).
Is it possible to have a function in vba that somehow uses SQL to run as fast as the SQL version but obviously having the advantage of being a function that all the queries can use, instead of recreating it in every query. Does this make sense?
Any help is much appreciated.