
Originally Posted by
Ajax
using querydefs in this way is not uncommon. Whether it is appropriate for your requirement is for you to decide. Providing you close the querydef objects and set to nothing, it should not have a detrimental effect on the stability of your application.
Okay thank you. I'll keep going with this strategy then.
At the moment I don't see the benefit - why have two criteria when you are selecting one based on a Boolean value in the same call? you might as well set that in the calling code
It's a shortcut. I just have the logic there once rather than in each calling code. At the moment I have about a dozen different functions that follow the same basic formula:
Code:
Public Function get_some_sum( group_id as long, optional exclude_id as variant = null )
Dim res As currency
res = ESum("select clause goes here", _
"from clause goes here", _
"where clause goes here", _
"alternate where clause goes here", _
IsNull( exclude_id ) )
get_some_sum = res
End Function
which to me feels a little cleaner than this in every function repeated:
Code:
Public Function get_some_sum( group_id as long, optional exclude_id as variant = null )
Dim res As currency
Dim criteria As String
If IsNull( exclude_id ) Then
criteria = "where clause goes here"
Else
criteria = "alternate where clause goes here"
End if
res = ESum("select clause goes here", _
"from clause goes here", _
criteria )
get_some_sum = res
End Function