Login
`
Templates, Tools and Utilities
|
||
Add a comment to an Icetips ArticlePlease add your comments to this article.
Please note that you must provide both a name and a valid email address in order
for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!
Back to article list Search Articles Add Comment Printer friendly Direct link ABC: Moving records up or down 1999-02-10 -- Jim Kane Newsgroups: TopSpeed.Topic.Design
> Throughout the CW environment there are up and down arrow buttons that
> change the order of items. I would like to implement that from within a CW
> application. Is there a clean way to do this?
This is my code from an up button on a file loaded browse on a form:
PageNum field was never shown so 'skips' didnt matter.
Keys:
by_formID
\_formid, PageNum - unique
by_pageId
\-PageID - unique
!Variables Required
!Save:PgId Long !Save the one field in the primary key
!CurPg Short !Save the Field ordering is on in the Choice() record
!OtherPg Short !Save the Field ordering is on in the Choice()-1 record
If Choice(?browse:2) !if anything is choosen in the box
!Get the choosen record in the listbox
Brw2.Updatebuffer() !Get the choosen record - dont arm watch
Save:Pgid = pg:PageId !Save the pageID of the choosen record
CurPg = pg:Pagenum !Save the pageNum of the Choosen Record
!Get the previous record
RESET(Brw2.View,Queue:Browse:2.ViewPosition)
If Brw2.Previous()<>Level:Benign then Select(?Browse:2);cycle. !reRead same record
if Brw2.Previous()<>level:benign then Select(?Browse:2);cycle. !no previous record
!Change the Previous record to have the same page number as the current record
!keys can not be unique
OtherPg=PG:PageNum !Save the pageNum for the previous record
Pg:PageNum = CurPg !Give this page the others number
Logout(2,FBPage) !Start a logout
If errorcode() then !On error reget the original record
PG:PageId=Save:Pgid
Access:FBPage.Tryfetch(Pg:By_pageID)
Select(?Browse:2)
Cycle !Abort
end
BreakLogout=False !Flag that no error happened yet
!Save the previous record with the new pagenumber
If Access:FBPage.TryUpdate()<>Level:Benign then
Rollback() !On error rollback and restore the original record
PG:PageId=Save:Pgid
Access:FBPage.Tryfetch(Pg:By_pageID)
Select(?Browse:2)
cycle
end
!Reget the original record and change it.
PG:PageId=Save:Pgid
IF Access:FBPage.Tryfetch(Pg:By_pageID)<>Level:benign then
!on error, rollback
Breaklogout=true
RollBack() !dont cycle - want to flush the view since something was saved
Else
PG:PageNum = OtherPG
IF Access:FBPage.TryUpdate()<>Level:Benign then
!On error RollBack
Breaklogout=true
Rollback()
end
End
!if no errors keep the changes
If not Breaklogout then
Commit()
End
!Flush the View and Reset the browse
Flush(Brw2.View)
BRW2.ResetFromFile()
BRW2.PostNewSelection()
!If there were multiple browses on the window then ThisWindow.Reset(1).
Select(Brw2.ListControl)
end
Down buttons a simple variation on the theme.
HTH,
---
Jim Kane
Today is November 23, 2024, 3:34 am This article has been viewed 35383 times. Google search has resulted in 71 hits on this article since January 25, 2004.
|
|