Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 2 Jahren, 10 Monaten
Letzter Beitrag:
vor 2 Jahren, 10 Monaten
Beteiligte Autoren:
Sammy Broeders, Fabrice Harari, DerekT, Eric Wiegert, Markus K., DarrenF

Change record number in database

Startbeitrag von Sammy Broeders am 27.08.2015 16:42


Is it possible to change the record numbers in a database file? It is a table with invoice lines and i need a function to change the order of lines. It is a table with direct acces.



Hi Sammy

What are your record numbers? Automatic IDs? Something else?
When you are saying "it is a table...", are you talking about a file, or about a table control in a window?

Best regards

von Fabrice Harari - am 27.08.2015 17:38

First thanks for your reply!
It is a data file with automatic rec numbers.

von Sammy Broeders - am 28.08.2015 08:36
Hi Sammy

I see

First I have to say that I would NOT use automatic identifier as line numbers for invoices, but I would have lines values set independant for each invoice.

Now, if you really want to change automatic IDs, you can by doing a hmodify on the record with the hforceautoID parameter .or hfixautoID, I can't remember which one to use in your case. So just lok for details in the help.

Best regards

von Fabrice Harari - am 28.08.2015 09:52
It is a temp file that i use. What is then the best way to move the order of the lines?

von Sammy Broeders - am 28.08.2015 11:38
Hi Sammy,

for the orderlines i use an own field which holds an index: If you add the first orderline it gets value 1, second orderline gets value 2 and so on.
If an orderline has to move up or down (i have two buttons for the reordering) then i switch the values.
But i don't use a table with direct access, i use a query and the orderlines are sorted by the index-field.


von Markus K. - am 28.08.2015 12:08
Hi again

personnaly, for all sort orders, I use a high precision numeric..

This allows me to add after or before a line by calculating the median value between the two lines (by example, adding a line between value 2 and 3 is line 2.5)

Mowing a line up can be done by switching values, of course but also by simply chaning one line value to an intermediate one. By example, if we have line 1 2 3 and 4 and want to move line 4 up 2 line, I just change sort order 4 by sort order 1.5...

Best regards

von Fabrice Harari - am 28.08.2015 12:53
I also use a process similar to what Markus mentioned. I just have a field on OrderLine called "Sequence" so that when you bring back the order lines (usually via a query), just ORDER BY Sequence :spos: ...and when you move the line up/down, you do as Markus says and swap the sequence number.

von DarrenF - am 28.08.2015 13:02

If it is a temp file then just load the contents to a memory table control recording the current desired positions in an int column ("Sequence") as Markus K advised, add some controls (buttons) to move the lines in the memory table similar to:

iTotCnt is int = MemTable..Occurrence
iCurPos is int = TableSelect(MemTable)
IF iTotCnt > 1 _AND_ iCurPos 1 THEN
MemTable.colSequence[iCurPos] = iCurPos-1
MemTable.colSequence[iCurPos-1] = iCurPos
ChkPosition() // Procedure to disable button controls depending upon position in MemTable

When the user is done/save just delete the temp file and do a HAdd to the temp file again

I'm sure there are a number of ways to solve this and every problem this is just one that came to mind.

Eric W

von Eric Wiegert - am 28.08.2015 13:16
Depends whether you need a permanent or temporary change to the order.

If permanent then does as already suggested with a sequence number in your file.

If temporary load your query result into an array and bind your table to this array.
You can then move the rows about using the 'ArrayMoveLine' function with buttons or DragnDrop foloowed by TableDisplay()

von DerekT - am 28.08.2015 14:24
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.