Import previous record data

kobiashi

Registered User.
Local time
Today, 15:45
Joined
May 11, 2018
Messages
258
Hi

I have a form, and an unbound subform in the form, when I create a new record, how can I import the previous record into the subform

Sent from my ONEPLUS A6003 using Tapatalk
 
I would probably bind the subform to a query that pulls the previous record.
 
kobiashi,

First, you need to understand that depending on how you ask the question, what you wan't doesn't exist. IF the record is from a table and you don't have an ORDER BY on the form, you cannot know what is the previous record because Access stores things in at best a semi-predictable order. There IS no reliable "previous record."

On the other hand, if you are binding the main form via a query that includes an ORDER BY, then there are a few ways to do this. If neither the main nor the sub are bound, you are just making trouble for yourself AND you are bypassing the whole point of bound forms, where Access does some of the heavy lifting for you.

Let's assume that there is a query for the main form. Your sub-form is supposed to hold the previous record. That kind of implies that the sub-form and main form will be similar if not identical. IF they are similar enough that they could BOTH use the same exact recordset for fill-in, then MAKE them use the same recordset (including the ORDER BY clause). THEN when you create a new record, make the sub-form's .Recordset do a .MoveLast, which SHOULD be the previous record if that ORDER BY is right.

Technically, you do this by doing the .MoveLast on the sub-form's .RecordsetClone, then copying the .Bookmark from the clone to the sub-form's .Recordset; i.e. move the clone then use its bookmark to move the recordset to match. As long as there is an ORDER BY in the .Recordsource SELECT query, you CAN identify a "previous" record.

The ONLY thing that would screw up the works is that you cannot save the new record prematurely, because then the sub-form would move to the (probably partially blank) new record rather than the previously saved record. I would also caution that you disallow the sub-form from editing the previous record, which involves setting the form properties to .AllowEdit=NO and most of the other .Allow properties also should be no.
 
Thanks doc_man, it doesn't matter if I have to make the sub form bound, I understand the need for it, it was just a thought that it may work unbound. Thanks for the help, I'll take a look at your suggestion.

Sent from my ONEPLUS A6003 using Tapatalk
 

Users who are viewing this thread

Back
Top Bottom