Ask Your Question

base auto populate new record

asked 2017-02-07 02:34:00 +0200

Dski gravatar image

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.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2017-02-07 03:06:21 +0200

Ratslinger gravatar image

updated 2017-02-09 09:32:14 +0200

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"
    "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.

edit flag offensive delete link more


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?

Dski gravatar imageDski ( 2017-02-08 02:14:03 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2017-02-08 02:38:51 +0200 )edit

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.

Dski gravatar imageDski ( 2017-02-08 18:11:00 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2017-02-08 19:47:29 +0200 )edit

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.

EasyTrieve gravatar imageEasyTrieve ( 2017-02-09 00:56:20 +0200 )edit

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 gravatar imageDski ( 2017-02-09 01:22:57 +0200 )edit

@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.

Ratslinger gravatar imageRatslinger ( 2017-02-09 07:18:04 +0200 )edit

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.

Dski gravatar imageDski ( 2017-02-11 18:11:44 +0200 )edit

answered 2017-02-09 04:20:59 +0200

EasyTrieve gravatar image

updated 2017-02-09 04:21:57 +0200

This manual, and this chart:


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

edit flag offensive delete link more


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

Dski gravatar imageDski ( 2017-02-11 18:05:16 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-02-07 02:34:00 +0200

Seen: 440 times

Last updated: Feb 09 '17