Help with Base Copy Field or Clone Record

I need help with the macro in this DB example.Base Copy Field or Clone Record - Example
Postby Arineckaig » Thu May 26, 2016 5:18 pm
CopyFieldCloneRecordExampleREV.odb

Debian 10 – LO 5.2.2.2 Split DB Wizard

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), T$(25)
oGridV = oEv.Source : oGridM = oGridV.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 = 0 to oGridM.Count-1
Name$(I) = oGridM.getByIndex(I).BoundField.Name
Value$(I) = oRS.Columns.getByName(Name$(I)).getString()
NEXT I
oRS.moveToInsertRow()
IF oGridM.Tag = “” THEN REM Clones all fields but leftmost
FOR I = 1 to oGridM.Count-1
oRS.Columns.getByName(Name$(I)).updateString(Value$(I)
Next I
ELSE T$() = Split(oGridM.Tag,";") REM Clones selected fields
For I = LBound(T$) To UBound(T$)
ColIdx% = Val(T$(I))
oRS.Columns.getByName(Name$(ColIdx%)).updateString(Value$(ColIdx%))
Next
END IF
End Sub

From the example it is from a MAIN FORM grid control with just one table to copy to.

  1. Since there is only one table,it doesn’t seem to have a table name to send data to.
    Where would a table name be put in the macro if many tables.
  2. Can it be used in a subform grid control with SQL as the content type.
    If so would it need changes.

Thanks, if this is easily doable it would be of great help.

Hello,

Whenever referring to someone else’s work/example/post, please provide a link:


Base Copy Field or Clone Record - Example

You state:

it doesn’t seem to have a table name
to send data to.

In the noted post, at the end of the fourth paragraph it states:

or pressing the Alt and + (num pad)
combination to clone any selected
record to the new record row.

The first few paragraphs in that post discuss the situation of records being entered needing only slightly different information. There this is about duplicating records within a table.

Your request seems to be about copying to one or more different tables AND a vague description of a form/subform (doesn’t matter which) based upon SQL - have no idea what this could entail.

Anyway, again based upon your requests, it would probably be best to write something completely from scratch and specifically to your needs.

You also stated:

Thanks, if this is easily doable it
would be of great help.

If you know how to write Base macros, it can be done. Not terribly difficult but probably time consuming. If you do not know how to write Base macros, it will be quite difficult.

Edit:

It is also questionable as to why you would be duplicating data in other tables. This is not how to use a relational database.