Hi
I have several records with "Opening" and "Closing". The
Opening are always the closing from the previous record.
Then those closing are the opening of the next record etc.
Is there a way to automatically copy Closing from the first
record into the Opening of the next record and so on?
Thanks
Databsae design courses teach the rule that if the data is
always the same as another item of data, you query it, you do
not store it in the table. It is a good rule, but like all
rules, made to be broken.
In the form where you enter the data, you need to set the
default value of opening to the value you entered for
closing. You would do this from the AfterUpdate event of the
control bound to your closing field in the table.
me.txtOpening.default = me.txtclosing.value
But that value will not persist if you close then reopen the
form, so you need to also set the default value for the
opening to the most recently entered closing in the Form_Open
event. I cannot give you a specific answer as to how to write
the Where Clause for the query as I cannot guess the
structure of the table, but you probably could use the
Dlookup() function to do this easily.
If for example, the date and time of the entry is stored, you
want the closing value associated to the maximum date in the
table, or the bigest Sequence Number...
something like
stWhereclause = "[Entrydate] = # & Dmax
("entrydate","thetableName") & "#"
me.txtOpening.default = Dlookup
("closing","thetablename",stwhereclause)