LOCAL loGrid, lcCurs, lcFld, lnIndex loGrid = SFT.pageframe1.page1.cont1.grid1 && Replace "pageframe1", "page1", "cont1", and "grid" with the actual names of the controls lcCurs = "fi" lcFld = "ref" IF lower(loGrid.RecordSource)==m.lcCurs and USED(m.lcCurs) && and type() plus hoist comparison outside ? * Find the column index by ControlSource FOR lnIndex = 1 TO loGrid.ColumnCount if lower(loGrid.Columns(lnIndex).ControlSource) == m.lcCurs + "." + m.lcFld * macro compile done once, oftem faster on recordset cmds update &lcCurs SET &lcFld = "Novaref" where empty(&lcFld) * Refresh the grid to reflect the changes loGrid.Refresh() EXIT && Exit the loop once "REF" column is found ENDIF ENDFOR if m.lnIndex > loGrid.ColumnCount ? "Column 'FI.REF' not found in the grid." endif ELSE ? "Invalid or empty cursor name in the grid's RecordSource." ENDIF READ EVENTS>Hi,
>LOCAL loForm, loGrid, lcCursorName, lnRow, lcControlSource, lcNewValue, lcReplaceCmd > >loForm = SFT && Get a reference to the active form (form with focus) >loGrid = loForm.pageframe1.page1.cont1.grid1 && Replace "pageframe1", "page1", "cont1", and "grid" with the actual names of the controls > >* Get the Cursor/Table name from the Grid's RecordSource property >lcCursorName = loGrid.RecordSource > >IF USED(lcCursorName) AND !EMPTY(lcCursorName) AND TYPE("lcCursorName") = "C" > * Find the column index by ControlSource > lnCol = 0 > FOR lnIndex = 1 TO loGrid.ColumnCount > lcControlSource = loGrid.Columns(lnIndex).ControlSource > IF lcControlSource = "FI.REF" > lnCol = lnIndex > EXIT && Exit the loop once "REF" column is found > ENDIF > ENDFOR > > IF lnCol > 0 > * Loop through the rows and modify the data in the underlying cursor > FOR lnRow = 1 TO _TALLY > IF VARTYPE(EVAL(lcControlSource)) = "C" && Check if the field is a string (character) > lcNewValue = "Novaref" && Replace with your desired new value > lcReplaceCmd = 'REPLACE ' + lcControlSource + ' IN (lcCursorName) WITH (lcNewValue) FOR RECNO() = lnRow AND EMPTY(EVAL("' + lcControlSource + '"))' > &lcReplaceCmd && Execute the REPLACE command > ENDIF > ENDFOR > ELSE > ? "Column 'REF' not found in the grid." > ENDIF >ELSE > ? "Invalid or empty cursor name in the grid's RecordSource." >ENDIF > >* Refresh the grid to reflect the changes >loGrid.Refresh() > >READ EVENTS >>