Endre
Registered User.
- Local time
- Today, 14:01
- Joined
- Jul 16, 2009
- Messages
- 137
Well, you learn something every day.
I have been developing Access since v1.1 and constantly learn new things, but this is a new one for me. Yes it's the "D" Functions - but for an interesting use.
For some reason I have stayed away from the them thinking that I can just open up a recordset and do the same things - but I have just found out their powerful use within queries and would like to share the following with you:-
I always have had a "problem" looping around recordsets and, when a field value changes in between records, to perform a particular function. For example: suppose I want to output a list of application forms to separate text files. And I want each object to appear on a different page. And each property of the object I want line separators to split them apart.
Or replicating the Reports function that allows you to "suppress duplicate values for consecutive data" - a variation on the attached will produce same effect.
It's not too difficult to do with VBA - you just need to be careful in your logic when you get to the last record, or when dealing with the first record - else you have to duplicate code or write multiple functions for this. And you are always comparing the next value with the current value (or previous value with current) and having to store your variables and reset them each time. It's just a schlepp that's all (Afrikaans slang used for "Pain in the @$!&")
However, I have just found that using "D"Functions in my queries eliminates all of this.
And I have managed to write a single query that "knows" when the field value in the next record is going to be altered.
In the above example the query can now state:
"For this record - this is the last Object in my form. SO close the text file I am writing to for this form and open up another text file please so we can start looking at the next set of objects on the new form and start writing those"
Or: "This property is the last property (but not the last object), so write separators and start a new page for the next object."
The main advantage of this is that this is a single query that is run once only. You just go down through the records till the end. And it is updateable too.
View attachment DFunctions.mdb
Attached is a Table with 4 fields (All 4 fields combined set the primary Key), and a single query that does all the above. I have not accumulated query formula as I would normally do - as it is currently shown makes it easier to understand.
I don't know why this is such a revelation to me
- does anyone know of a better way to do this without VBA? (It runs a little slow with 10,000 records...)

For some reason I have stayed away from the them thinking that I can just open up a recordset and do the same things - but I have just found out their powerful use within queries and would like to share the following with you:-
I always have had a "problem" looping around recordsets and, when a field value changes in between records, to perform a particular function. For example: suppose I want to output a list of application forms to separate text files. And I want each object to appear on a different page. And each property of the object I want line separators to split them apart.
Or replicating the Reports function that allows you to "suppress duplicate values for consecutive data" - a variation on the attached will produce same effect.
It's not too difficult to do with VBA - you just need to be careful in your logic when you get to the last record, or when dealing with the first record - else you have to duplicate code or write multiple functions for this. And you are always comparing the next value with the current value (or previous value with current) and having to store your variables and reset them each time. It's just a schlepp that's all (Afrikaans slang used for "Pain in the @$!&")
However, I have just found that using "D"Functions in my queries eliminates all of this.
And I have managed to write a single query that "knows" when the field value in the next record is going to be altered.
In the above example the query can now state:
"For this record - this is the last Object in my form. SO close the text file I am writing to for this form and open up another text file please so we can start looking at the next set of objects on the new form and start writing those"
Or: "This property is the last property (but not the last object), so write separators and start a new page for the next object."
The main advantage of this is that this is a single query that is run once only. You just go down through the records till the end. And it is updateable too.
View attachment DFunctions.mdb
Attached is a Table with 4 fields (All 4 fields combined set the primary Key), and a single query that does all the above. I have not accumulated query formula as I would normally do - as it is currently shown makes it easier to understand.
I don't know why this is such a revelation to me
