Base Copy Field or Clone Record - Example

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Base Copy Field or Clone Record - Example

Post by Arineckaig »

From time to time there have been requests to match the MS Access facility whereby pressing a key combination automatically copies to a new record the data recorded for that particular field in the previous record.

A macro is clearly required but, due to the idiosyncrasies of the OpenOffice API, portability encourages coding that eschews references to a named or any object that may be specific to a particular application.

For several years I have used Base for a book-keeping application where often new transactions differ in only minor respects from previous records. A macro has permitted data from any selected record to be cloned to the new record entry buffer where changes may be made before a final save to the database.

In the attached demo that macro has been extended to permit either cloning a whole record or copying a single field from its previous record as found in MS Access. The macro permits either pressing the Alt and ' key combination to copy to any selected field (new or existing) the data from the corresponding field in its immediate predecessor, or pressing the Alt and + (num pad) combination to clone any selected record to the new record row.

The macro is offered as is, without proper testing or serious elimination of the inevitable bugs. I would welcome criticisms or comments, but even more discovery of errors.

General design principles
1. The macro presupposes a Table/Grid form control is used being the most likely format for the cloning and display of several records.
2. Both macros are triggered by the Key Released event in the Table/Grid form control. The Alt key is chosen as the modifier key because I was unable to get the Cntrl and ' key combination suitably recognised by the AOO API
3. Further fields may be copied from the same row by selecting another field and pressing the Alt and ' combination to repeat the macro.
4. Care is required as in Base any change of the record pointer will automatically flush the output buffer to a saved record in the database: for this reason a cloned resultset is used in the macros for certain actions.
5. The Base API generally renders it simpler to work with fields in the data set that underlies the form than with the displayed columns of a Grid form control.
6. The Base API permits virtually all data-types in the data-set that underlies a form to be read and updated as if they were strings.
7. For demo purposes the macro comprises two distinct operations triggered depending on the respective key combination from the same event. In a real application it might well be preferable to use one or the other and to adjust the coding accordingly.

Issues
1. Any attempt to copy the Primary Key field will cause an error when an attempt is made to save the modified record. For this reason the macro assumes the Primary Key is located in the left-hand column (index=0) of the grid form control and data in that column is not cloned. If there is no PK field in the grid and all columns are to be cloned a couple of minor changes are required in the coding. Alternatively an SQL query (see the query in the demo) could be used to create an array that would trap and prevent cloning any PK field.
2. Initially an incorrect value may be displayed where a time column in the grid is linked to a time-stamp field in the database. The correct value, however, will be shown as soon as the modified record is saved.

Later edit: The 'cloning' macro can be extended to permit either all fields or a specified selection of fields to be copied to the new record row - see my second post below in this thread together with an updated demo file.

Code: Select all

REM  *****  BASIC  *****

Sub CopyField(oEv as Object)
REM Aborts unless Alt and ' key or ALT and + (num pad key) pressed
	IF  (oEv.KeyCode=1287 AND oEv.Modifiers=4) THEN CloneAnyRecord(oEv) : Exit Sub 
	IF  NOT(ASC(oEv.KeyChar)=39 AND oEv.Modifiers=4) THEN Exit Sub
	oGridV = oEv.Source 
	oForm = oGridV.Model.Parent
	oColNum = oGridV.getCurrentColumnPosition()
	oRS = oGridV.Model.getRowSet() : CloneRS = oForm.createResultSet()
	IF oRS.Row=1 THEN Print "No previous row to copy from" : EXIT SUB
	IF oRS.IsNew THEN 
		CloneRS.last()
	ELSE 
		CloneRS.previous()
	END IF
	FldName$ = oGridV.getByIndex(oColNum).Model.BoundField.Name
	FldValue$ = CloneRS.Columns.getByName(FldName$).getString()
	oRS.Columns.getByName(FldName$).updateString(FldValue$)
End Sub

Sub CloneAnyRecord(oEv as Object)	'Called from CopyField [Alt and + numpad key]
	Dim Name$(25), Value$(25)
	oGridM = oEv.Source.Model	
	oForm = oGridM.Parent
	oRS = oGridM.getRowSet()	
	CloneRS = oForm.createResultSet() : CloneRS.Last()	'Clone ensures RowSet fully loaded
	IF oForm.IsNew THEN oRS.Last()	
	FOR I = 1 to oGridM.Count-1		
		Name$(I) = oGridM.getByIndex(I).BoundField.Name
		Value$(I) = oRS.Columns.getByName(Name$(I)).getString()
	NEXT I	
	oRS.moveToInsertRow()			
	FOR I = 1 to oGridM.Count-1
		oRS.Columns.getByName(Name$(I)).updateString(Value$(I)
	Next I
End Sub
Attachments
CopyFieldCloneRecordExample.odb
(36.97 KiB) Downloaded 895 times
Last edited by Arineckaig on Sun May 29, 2016 8:40 pm, edited 2 times in total.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Base Copy Field or Clone Record - Example

Post by UnklDonald418 »

Thank You! This is what I have been seeking. So far, it works on every form and data type I have tried.
I was a little surprised to see that you used the RowSet to accomplish this. So, on top of being functional it is also educational.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Base Copy Field or Clone Record - Example

Post by Arineckaig »

For many practical applications it may be preferable that not all fields should be included in the cloning of a record: for example, leaving a field empty in the new record tends to prompt the user to enter new data and thus avoids the risk of inadvertently saving such values unchanged when they should be updated in the new record. For this reason the macro has been modified to permit cloning either a selection or all the fields.

The attached file demonstrates this alternative by adding a form document that differs in only one respect from the original: the “Additional information” property of its grid form control holds an index list of the grid columns to be copied with each index number delineated by a semi-column. In this example the list comprises 1;2:3;6;8;9 which means (with an index base=0) the values in the second third fourth seventh ninth and tenth columns only will be cloned to the new record. If the “Additional information” property of the grid control is empty, the macro still clones the values in all fields, other than the leftmost as it may often hold a PK field.

If the “Additional information” property is already required in the grid control for another purpose it should be possible in the form document to create a hidden text box form control to act as a substitute for this purose as described at this MS Access website. In that case the relevant lines in the macro will require some adjustments.
Attachments
CopyFieldCloneRecordExampleREV.odb
Added clone selected fields option
(47.37 KiB) Downloaded 830 times
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
ThisWas
Posts: 5
Joined: Fri Jun 17, 2016 4:40 am

Re: Base Copy Field or Clone Record - Example

Post by ThisWas »

[Solved] Q: Modification for use with Form view, not Table/Grid?

Arineckaig, I was excited to test your code as it is almost what I need.
My problem is that my application is data entry with a Form view and your very first design principle is "1. The macro presupposes a Table/Grid form control".
My users expect a Form (single record) as they're migrating from FileMakerPro set up with a Form view.
Can your macro be modified to work with a Form view?
I copied the code snippet from your sample database to mine and both Alt+' and Alt++ are ignored in mine; they work perfectly in yours, of course.
Last edited by ThisWas on Mon Jun 27, 2016 12:37 am, edited 1 time in total.
LibreOffice 5.1.3 Win7-64
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Base Copy Field or Clone Record - Example

Post by Arineckaig »

Can your macro be modified to work with a Form view?
Certainly it could be modified but there would have to be substantial changes. The OpenOffice API is comprehensive, but generally does not lend itself to simple copying of code from one application to another. Form controls contained within a Grid control have properties and methods that differ significantly from controls contained directly within a Data Form.

Sorry not to be more helpful, but Star Basic macros tend to be specific: the underlying principles can be readily transported, but I suspect the detailed coding requires design beyond my skills if it is to be generic.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
ThisWas
Posts: 5
Joined: Fri Jun 17, 2016 4:40 am

Re: Base Copy Field or Clone Record - Example

Post by ThisWas »

Thank you! I'll save your code for future use with a Table/Grid. I like your Alt-key implementation.

For my Form view record cloning I'll implement the button & macro written by DACM in 2009:
viewtopic.php?f=100&t=40580
LibreOffice 5.1.3 Win7-64
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Base Copy Field or Clone Record - Example

Post by RPG »

Hello

[Solved] Having problems with hasFocus() (View topic)

Maybe you can use the macro in the link. Look at the end.
It copies only a simple field in the current control. You have to set an event for all the fields you want copy.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Base Copy Field or Clone Record - Example

Post by Arineckaig »

For what it may be worth I have attached a demo form that permits individual fields to be copied from any previous record: it works with either a new record or an existing one. The macro is triggered by entering Alt+' key in any form control whose key released event is set to call the macro.

A macro that clones data from a record generically for all the form controls in a data form should be possible but the coding will require further work if it is to avoid specific reference to named form controls.

Later Edit: 22 June 2016
Merely for the sake of completeness, despite its serious limitations but in reply to the request:
Can your macro be modified to work with a Form view?
the attached demo file has been updated to include also, as an alternate option, the cloning a complete record by entering the Alt and +(num pad) key combination in any form control whose key released event has been set to trigger the macro.

The primary key, and any other field in the database that does not permit duplicate values, have to be excluded from the new cloned record. This is a somewhat more complicated task compared with using a grid form control: a line of code in the demo macro lists the names of those database fields whose values are NOT to be cloned as a semi-colon separated string of field names:

Code: Select all

xCloneField$ = "ID;Amount;LastName"
In this example the effect is leave three fields (the PK “ID”, the “Amount” and the “LastName” fields) empty after cloning a new record. Hence if the macro is to be used in any other application that string should be adjusted to include the actual names of the database fields whose values are not to be cloned by the macro.
Attachments
DataForm-CopyFieldCloneRecord.odb
Revised version to include cloning chole record option
(27.49 KiB) Downloaded 932 times
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
ThisWas
Posts: 5
Joined: Fri Jun 17, 2016 4:40 am

Re: Base Copy Field or Clone Record - Example

Post by ThisWas »

Arineckaig, your "DataForm" example is brilliant! It works very well in my Forms-based implementation.
I modified the Clone-Entire-Record logic to list the key fields which are not to be cloned, per your instructions.
I also changed the key associated with Clone-Entire-Record to the Accent Grave key as our end user's ThinkPad doesn't have a numeric keypad to support Alt and + (num pad). On our U.S. keyboards the Accent Grave key is easily accessible in the top right of the keyboard and resembles the single quote key so I can tell the end users to use one key for field-level duplication and the other for record-level duplication.
Thank you for all your good work! I'm sorry it took me so long to implement and test your solution.
LibreOffice 5.1.3 Win7-64
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Base Copy Field or Clone Record - Example

Post by Arineckaig »

Many thanks for reporting back -am greatly relieved that it has generally met your requirements but for cloning records in Base, as you will have seen, my preference remains for using a Grid form control as the starting point.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Base Copy Field or Clone Record - Example

Post by Villeroy »

The form layout should not matter at all when you clone one record of the form's underlying record set. I just wonder what the macro is doing. I set a stop mark hit Alt+', the stop mark indicates that the code is actually called, stepping through the code seems to do a lot of incomprehenisble stuff and in the end the form looks exactly the same. Even in grid view, I do not see anything cloned.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Base Copy Field or Clone Record - Example

Post by Arineckaig »

Even in grid view, I do not see anything cloned.
Villeroy, my apologies but the problem could be due to a variety of issues:
1. bugs in the code that my limited tests have failed to uncover;
2. excessive complication from combining two routines - cloning a whole record or copying just a single field;
3. the key codes for my keyboard may be non-standard;
4. my brief explanation and instructions lack clarity.
The form layout should not matter at all when you clone one record of the form's underlying record set
The form layout does not matter but if a form control event is used to trigger a macro it may be relevant in that the properties and methods of a grid control differ significantly from those of other form controls.

There are four key differences. First, the grid control key released event will recognise the location of a key entry in any whole row or any single field in a row whereas for other form controls to be recognised that event has to be individually set for each form control. Secondly, the grid control has direct access to its underlying rowset whereas for other form controls the rowset can only be obtained through the containing data form. Thirdly, the grid control's elements comprise solely the columns it contains to permit simple enumeration routines, whereas enumerating form controls requires these to be distinguished from the many other objects that may well be contained in a data form. Fourthly, the grid control has its Tag property that can be useful for storing a list of fields to be included or excluded from the clone whereas a data form has no such porpoerty.
I just wonder what the macro is doing
To avoid excessive length the following comments only cover cloning a record from a grid form control

Code: Select all

Sub CopyField(oEv as Object)
REM Aborts unless Alt and ' key or ALT and + (num pad key) pressed
	IF  (oEv.KeyCode=1287 AND oEv.Modifiers=4) THEN CloneAnyRecord(oEv) 
Key trap routine to call the CloneAnyRecord macro if ALT and + numpad key combination recognised.

Code: Select all

Sub CloneAnyRecord(oEv as Object)	'Called from CopyField [Alt and + numpad key]
	Dim Name$(25), Value$(25)
	oGridM = oEv.Source.Model	
	oForm = oGridM.Parent
	oRS = oGridM.getRowSet()	
	CloneRS = oForm.createResultSet() : CloneRS.Last()	
                          'Clone ensures RowSet fully loaded
oRS is the RowSet that underlies the grid control and its Row property will hold the row number for whatever row was selected to be cloned. To prevent a potential bug if the underlying RowSet has not yet been fully loaded, CloneRS creates a cloned RowSet and moves that record pointer to the last row to ensure it is fully loaded. A cloned RowSet is used for this purpose to avoid screen activity and to ensure oRS still points to the source row that is to be cloned.

Code: Select all

IF oForm.IsNew THEN oRS.Last()
This line permits the macro to be triggered even from the new row where it is presumed the row to be cloned is the last row: the record pointer is moved accordingly.

Code: Select all

FOR I = 1 to oGridM.Count-1		
		Name$(I) = oGridM.getByIndex(I).BoundField.Name
		Value$(I) = oRS.Columns.getByName(Name$(I)).getString()
	NEXT I
Enumerate through all the columns of the grid other than the leftmost (zero index) which is presumed to be a PK or no duplicate field: first, to get the name of the relevant bound field in the underlying RowSet of the database and secondly to get the value held in that field of the RowSet.

Code: Select all

oRS.moveToInsertRow()			
	FOR I = 1 to oGridM.Count-1
		oRS.Columns.getByName(Name$(I)).updateString(Value$(I)
	Next I
Finally move the record pointer to the new row and fill the values from the cloned record into the relevant fields of the RowSet buffer. These values will then display suitably in the new record line of the grid control but the data is only in the output buffer and can still be modified until finally written/saved to the database as a new record.

It would appear to be a feature of the Base API that values can always be read from, and assigned to, columns in a RowSet using the getString() and updateString() methods irrespective of the actual datatype of the database field. In this respect the Base GUI appears remarkably flexible and very often a Formatted form control is an effective tool for displaying dates, times etc in a form document.

The macro for copying just the value of a single field is similar. On the other hand if the clone/copy macros are to be triggered from a key event in a form control other than the grid control the routines have to be somewhat different. The demo file offered for that purpose is far from properly tested.

My apologies, Villeroy, for the length of this reply but your post did raise a number of questions for which I had no simple answers.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
Koa
Posts: 12
Joined: Sun Jan 15, 2017 11:53 pm

Re: Base Copy Field or Clone Record - Example

Post by Koa »

Arineckaig, Thanks for this!

It was just what I was looking for. It works great! Saved me having to write it. I really appreciated your building this and am so glad I found your code.

I also tried to get this to work w/ Cntr, rather than Alt to try and make it more standard. I suspect the fact that list boxes eat control characters is a bug and plan to report it as such. (Edit: See bug https://bugs.documentfoundation.org/sho ... ?id=107356 ). Too bad, because it makes it non-standard from other similar features in Calc & Access that use Ctrl prefix.


Two questions: 1) Care to say more about this line, as it's still unclear to me what it does. It seems to work ok without it:

Code: Select all

CloneRS.Last()
2) Any special reason to use Key released over Key pressed event?


Here are a few things I think that could be improved in your code:

* oColNum is not an object, but rather an integer. It 'o' prefix is misleading. It should be named iColNum. I renamed mine iColumn, as the "Num" is now redundant given the i prefix.


* Your missing a closing paren in this line near the end. I didn't realize that Basic would ignore missing closing parens, and not throw a syntax error:

Code: Select all

     oRS.Columns.getByName(Name$(I)).updateString(Value$(I)

* If you want to avoid the fixed array (25) size limit you can do this using ReDIM Preserve syntax as follows:

Code: Select all

	Dim Name$(), Value$()
	For I = 1 to oTableModel.Count-1
		ReDIM Preserve  Name$(i)	: Name$(I)	= oTableModel.getByIndex(I).BoundField.Name
		ReDIM Preserve Value$(i)	:Value$(I)	= oRS.Columns.getByName(Name$(I)).getString()
	Next I

* You also might want your Subs to be Private Sub .. to avoid future conflicts

Below I offer back to you my rewrites so you can take a look. I rewrote it for my own personal use, and thus to my personal coding styles and tastes. Take what you want, and leave the rest. Thanks again!

Code: Select all

Option Explicit	'BASIC	###### BASE TABLE COPY UTILITY ######

'Clone last field, or current record:
'
'	Select a field in any new or existing record and type the Alt' to copy the corresponding field to from its immediate predecessor; or
'	Select any existing record and type Alt+ (num pad) to clone the whole record to a new record.
'
'You can edit new data or abort the changes by pressing ESC before the record is saved.
'
'Issues:
' * An attempt to copy a Primary Key will cause an error when a new or modified record is saved.
' * A time-stamp column, or a time column linked to a time-stamp field in the database, may initially display incorrect times. 
'   The correct value, however, will be saved automatically and shown as soon as the new or modified record is saved.


Private Sub TableKeyPressed(oEvent as Object)	'CloneFieldOrRecord
'	Dim KM1 As Integer	: KM1 = com.sun.star.awt.KeyModifier.MOD1	'Ctrl KeyModifier  (doesn't work in list boxes)
	Dim KM2 As Integer	: KM2 = com.sun.star.awt.KeyModifier.MOD2	'Alt  KeyModifier

	If oEvent.Modifiers=KM2 AND oEvent.KeyCode=com.sun.star.awt.Key.ADD	Then CloneRecord(oEvent) :Exit Sub ' Plus sign on numeric keypad
	If oEvent.Modifiers=KM2 AND oEvent.KeyChar="'"						Then CloneField( oEvent) :Exit Sub
End Sub


Private Sub CloneField(oEvent as Object)
'	Dim KM1 As Integer	: KM1 = com.sun.star.awt.KeyModifier.MOD1	'Ctrl KeyModifier  (doesn't work in list boxes)
	Dim KM2 As Integer	: KM2 = com.sun.star.awt.KeyModifier.MOD2	'Alt  KeyModifier

	If oEvent.Modifiers= KM2 AND oEvent.KeyCode=com.sun.star.awt.Key.ADD	Then CloneRecord(oEvent) :Exit Sub ' Plus sign on numeric keypad
	If oEvent.Modifiers<>KM2 OR  oEvent.KeyChar<>"'"						Then 					  Exit Sub

	Dim oTable		As Object	:oTable		= oEvent.Source 
'	Dim oForm		As Object	:oForm		= oTable.Model.Parent
	Dim oRS 		As Object	:oRS		= oTable.Model.getRowSet() 
	Dim oRS_clone	As Object	:oRS_clone	= oTable.Model.Parent.createResultSet()	'Clone ResultSet of the Row set
	'Note: a RowSet can be in two modes:  prior to running, or  after running which is called the ResultSet

	If oRS.Row=1 Then Exit Sub	'or: ..Then Print "No previous row to copy from" : Exit Sub

	If oRS.IsNew _
		Then :oRS_clone.last()
		Else :oRS_clone.previous()
	END If

	'Because the column order is different between RS and clone use name rather than index 
	Dim FldName$:	FldName$  = oTable.getByIndex(oTable.getCurrentColumnPosition()).Model.BoundField.Name
	
	oRS.Columns.getByName(FldName$).updateString( oRS_clone.Columns.getByName(FldName$).getString() )
End Sub


Private Sub CloneRecord(oEvent as Object)	'Called from CopyField [Alt and + numpad key]
	Dim oTableModel		As Object	:oTableModel 	= oEvent.Source.Model	
	Dim oForm			As Object	:oForm			= oTableModel.Parent
	Dim oRS				As Object	:oRS			= oTableModel.getRowSet()	
	Dim oRS_clone		As Object	:oRS_clone		= oForm.createResultSet() : oRS_clone.Last()	'Clone ensures RowSet fully loaded
	
	'Get names and values from RowSet	
	If oForm.IsNew Then oRS.Last()	'If new record, then get the last record.  Otherwise get the current record.

	Dim I				As Integer	'count of columns found
	Dim Name$(), Value$()
	For I = 1 to oTableModel.Count-1
		ReDIM Preserve  Name$(i)	: Name$(I)	= oTableModel.getByIndex(I).BoundField.Name
		ReDIM Preserve Value$(i)	:Value$(I)	= oRS.Columns.getByName(Name$(I)).getString()
	Next I
		
	'Write values into new record
						oRS.moveToInsertRow()
	
	For I = 1 to oTableModel.Count-1
		oRS.Columns.getByName(Name$(I)).updateString(Value$(I))
	Next I
End Sub
Last edited by Koa on Sun Apr 23, 2017 2:16 pm, edited 1 time in total.
LibreOffice 5.2.5.1 on Linux Jessie 8.6
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Base Copy Field or Clone Record - Example

Post by Arineckaig »

It is almost a year since the original posting, so any comment will be as unreliable as my memory.
Two questions: 1) Care to say more about this line, as it's still unclear to me what it does. It seems to work ok without it: CloneRS.Last()
I suspect there would be two circumstances where the clone of the ResultSet is helpful: first, if copying data from ANY record to a NEW record and to ensure the entire row-set has been read into memory, movement by the clone ResutlSet avoids distracting GUI screen activity; secondly, if copying a single field from its previous record the clone permits further fields to be similarly copied without triggering save(s) of the modified record that would be caused by the GUI record pointer moving each time - not essential but does permit scope to abort or adjust the new data before a final commit to the database.
2) Any special reason to use Key released over Key pressed event?
No great reason but tends to permit an abort or change of mind when an object has been selected: for example, by releasing one part of a key combination or by moving way from the control can often avoid an unintended event.
I also tried to get this to work w/ Cntr, rather than Alt to try and make it more standard.
FWIW, my keyboard is unable to register any key event when the Cntrl and ' key combination is used: hence, seen as a feature rather than a minor irritation.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Base Copy Field or Clone Record - Example

Post by Villeroy »

Code: Select all

2) Any special reason to use Key released over Key pressed event?
This is standard also with mouse events. In this particular case it prevents the creation of hundreds of new records when you keep the key pressed.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Base Copy Field or Clone Record - Example

Post by Arineckaig »

Many thanks Viilleroy - I had quite forgotten that important point.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
Post Reply