base auto populate new record

I would like to be able to clone some of the text data fields from the last record when I go to a new record. It looks like the only way to do this is with a macro but I can’t figure out how to trigger the macro. Could one of the record action or record change events be used to trigger a macro to do this?

I have seen some examples that use a button in the form (Investment_Tracking.odb and Quality_Assurance.odb) but I would like it to happen when I click certain buttons in the Form Navigator toolbar. Specifically, I would like it to run my macro when either the New Record button is clicked or when the Next Record button is clicked when I am at the last record.

Use the Form (or subform) Events to capture before & after record events. In the macro, you need to check the IsNew property to see if True or False to determine if you are at a new record so you can move in your field values saved from last record something like:

If myForm.IsNew Then
    "it's a new record"
else
    "not a new record"

So, before record change save your data. After record change, if new, move in your saved data.

Edit 2/8/17:

Attached is a simple .odb with one table and one form. The table has three fields: ID (auto-increment), Address (text) and City (text). In the form, whenever you go to a new record, the city field will be filled in with the city data from the record you came from. So if there are ten records in the table and you are on record 2 then jump to enter a new record, the value from record 2 will fill the city field. Any further checking of data is purely up to you since you know what you are looking to complete. This should get you started.

PassRecordData.odb - added some comments to code.

I appreciate your help. One problem that I am having is the documentation isn’t very good. Is there someplace that I can go to find the properties and methods for Event and Form objects?

Macro type documentation is spread all over the place. You can find many links on this post: click here. Pitonyak’s Open Office Macros Explained (OOME) is the probably the most referenced. There are a couple of object inspection tools - MRI (the one I typically use) & X-Ray.

I’ve been playing with X-ray. I didn’t try MRI because it requires python but I might give it a try.

Is there a way to determine what event triggered the macro? I haven’t been able to figure out how to do this if it is possible. Currently I have a macro for each of the before and after events that I have used to determine the event.

First, on MRI you just need to install the extension. Also the post of documentation has a link (under MRI) for instructions & tutorial. MRI & X-Ray are fairly similar. For events you could examine oEvent for the source but I really don’t think this is what is wanted. You probably don’t understand my opening statement in the answer. When you examine a Form or subForm properties in edit mode, there is a Tab Events. That is where you point to your macros.

First, for MRI, I think the best help is here. Once using MRI, you can place the cursor on a Properties, Methods, etc. line and hit the “IDL Ref.” button to get web page help for most all properties and methods. The help on these is not extensive, but after some digging you will start to find your way around.

Ratslinger, I have been pointing to macros in the Events tab. I think that I will try MRI.
EasyTrieve, I’ve looked at the IDL Reference but I find the information to be somewhat cryptic.
I probably need to spend more time digging.

@Dski contemplating your statements and subsequent questions it appears you are somewhat new to LO macros in Base. It is not an easy task even after spending time with it. There are a lot of different aspects to comprehend even to get what seems like a simple task completed. To give you a head start, I’ve attached a sample in my original answer.

Thanks for you help and the example database. I’ve spent the last couple of days just experimenting with macros. I’ll get there eventually and will let people know what I came up with.

This manual, and this chart:

helped me get a framework on how the objects are connected.

Thanks, I’ve downloaded a copy. It will take me some time to get through it.