Reputation: 201
I'm not certain this is possible but must ask. No amount of experimentation or time with Google has revealed a solution.
I am working with a MS Access query having self-joined data. One of the query's fields is an aliased field expression concatenating a field's value for each table instance, e.g., [tblFoo_1].[Bar] & "." & [tblFoo].[Bar]
. The real-life case does some transformation of each instance of the [Bar]
field via some functions before doing the concatenation.
I have a string function that, with a few parameters (table name, field name, and self-join depth), returns a valid field expression string having a few calls to other functions. I.e., the function concatenates the names of these other functions and their derived parameters into the string it returns, so the SQL statement does successfully call those functions. The returned string works like a charm but requires being pasted into the field definition in query design view. If possible, I'd rather call a parameterized function directly from the field definition, something like Alias: ConcField("tblFoo", "Bar", 2)
The problem ultimately is that, while I can define a parameterized function to return a field's identifier, e.g., [tblFoo].[Bar]
and the identified field's value when the function's name and its derived parameters are concatenated into the field expression string, I can't seem to figure out how to define a parameterized function that will evaluate the derived identifier for the current record to return the identified field's value, when that function is called directly from the field definition.
Clearly, Access SQL can handle the function calls because the generated string itself works as intended. So, this may simply be a matter of constructing the entire SQL statement in code rather than in the query designer. Put otherwise, the problem simply may be (a) calling a parameterized function from the field definition box of the query designer because of the latter's limitations, rather than (b) calling a parameterized function from Access SQL. Still, it would be quite helpful to know whether and how such a function can be defined.
What hasn't worked is a variety of tricks to coerce evaluation in the query or the functions, and kicking out to a separate recordset via DLookup() and otherwise. Perhaps there is a subquery angle but I can't conceptualize it.
Thanks for any constructive thoughts.
Upvotes: 1
Views: 56