Setting Values

CanWest

Registered User.
Local time
Today, 12:41
Joined
Sep 15, 2006
Messages
272
Ok this one is way beyond my skill set.

In Form1 I have a Save button
In Form Two there is a subform

I need the value of a control on Form 2 to be set to the value of a field in the LAST record in the subform. If there are no records in the subform then the value needs to be null.

I know this is probably very easy but I just can not get my head around it
 
You could test;
Code:
Me.RecordSet.RecordCount = 0
to determine if your sub-form had any records in it, then if it did you could use the DLast() function to determine the value of that record that you want.

Note:
You will need to replace Me in the above code with the correct reference to the sub-form dependant on where you are addressing it from.
 
You could test;
Code:
Me.RecordSet.RecordCount = 0
to determine if your sub-form had any records in it, then if it did you could use the DLast() function to determine the value of that record that you want.

FYI - Do NOT use DLast or DFirst unless you want the absolutely last or first record you added. The sort order of the records or sort on query doesn't make a difference. See here for more about it.

So, if the last record you entered is the one you want then DLast can do that. If you want the last record in the ordered set (which might not be the last record entered) then you do not want to use DLast.
 
Hadn't thought of that :eek: So in that case you I guess the DLookup() function would be a better bet :o

Or depending on how you sort it and what fields are available you can use DMAX as well. I like to have a date/time stamp on my records so that I can use that for ordering if necessary. But that kind of replicates the DLAST function if you want the last record entered. If you want an order on a specific item then you might need to use DLookup.
 

Users who are viewing this thread

Back
Top Bottom