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