[Solved] Cancel insert row

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
bvdbos
Posts: 11
Joined: Sun Jul 13, 2008 9:07 am
Location: Helmond, Netherlands

[Solved] Cancel insert row

Post by bvdbos »

Is it possible to cancel inserting a new record in base? I use the following code which works well for records which haven't changed and records which have to be updated:

Code: Select all

  if NOT oForm.IsModified() then       'no modifications to record, only works on pre-existing records
    iAnswer = 6 
  else
    iAnswer=MsgBox("Wijzigingen opheffen?",51,"gegevens gewijzigd")     'record is modified, ask to cancel changes.
  end if

  if iAnswer = 6 then        'cancel saving to database
    if (oForm.isNew) then       'if in insert-row (new record chosen)
      oForm.deleteRow()        'cancelrowupdates only works for pre-existing records, how do I do this?
    else      'not in new mode means in edit mode
      oForm.cancelRowUpdates()        'cancel changes on pre-existing record works ok
    endif
  elseif iAnswer = 7 then         'save changes to database
    if (oForm.isNew) then oForm.insertRow else oForm.updateRow()         'save to new record or update pre-existing record
  else
    exit sub         ' assume cancel -> don't save changes when in new mode
  endif
The oForm.deleteRow() doesn't work as this may not be used when in new records. oForm.cancelRowUpdates works only on pre-existing records (function sequence error). Perhaps I should first save the current record and then delete it right away? But apparantly this doesn't work either?

Code: Select all

    if (oForm.isNew) then
    bm=oForm.Bookmark
    oForm.insertRow()
    oForm.absolute(bm)
    oForm.deleteRow(bm)
    else 
    oForm.cancelRowUpdates()
    endif
or even simpler

Code: Select all

    if (oForm.isNew) then
    oForm.insertRow()
    oForm.deleteRow
    else 
    oForm.cancelRowUpdates()
    endif
Does anyone have a tip to get this working?
Last edited by bvdbos on Fri Aug 01, 2008 11:36 pm, edited 1 time in total.
User avatar
bvdbos
Posts: 11
Joined: Sun Jul 13, 2008 9:07 am
Location: Helmond, Netherlands

Re: Cancel insert row

Post by bvdbos »

I kinda solved this by using oForm.relative(0). After this a table-control which holds the records of the current form doesn't get updated (it shows an extra line) so I have to use an oForm.reload. Even better behaviour would be if the table-control jumps back to the record which was selected before the new-record command was issued but this is a relative minor issue which I'll tackle after the basis of my application works. So the code I use for cancelling a new record:

Code: Select all

    oForm.relative(0)    
    oForm.reload
    oForm.last
I can't use movetocurrentrow() or previous(), they both throw a "function sequence error".
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: [Solved] Cancel insert row

Post by MTP »

I was trying to do this on an add data only form, where relative(0) doesn't move off the current record. I ended up using instead oForm.beforeFirst, and it worked great. Thanks for the tip about moving the cursor!
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: [Solved] Cancel insert row

Post by RPG »

Hello

I think when you want do those things as in this thread it is maybe good to use the interface Xformcontroller. It can also be good to use the interface xFormoperations

http://www.openoffice.org/api/docs/comm ... oller.html

http://www.openoffice.org/api/docs/comm ... tions.html

When you read the description in both links then you can read a lot of testing is done for you. I have not have tested the code below. But it is as example

Code: Select all

sub Storerecord(oEvent as object)
'use event before record change
dim oFormFeature
dim oFormOperations
dim iAnswer
oFormFeature = com.sun.star.form.runtime.FormFeature

select case  oEvent.Source.implementationname
' this sub is called twice. We need only to handle for the formcontroller
	case "org.openoffice.comp.svx.FormController" 
	' we have now the controller
	
		iAnswer= MsgBOX ( "Change Record",(4 or 256) ,"You want change the reocrd") 
		select case  iAnswer
				case 6 ' Yes do nothing
				case 7
					oFormOperations=oEvent.Source.FormOperations
					'oFormOperations.execute(oFormFeature.MoveToPrevious)
					oFormOperations.execute(oFormFeature.UndoRecordChanges)
				case else 
					print "wrong value"
		end select
					
	case "com.sun.star.comp.forms.ODatabaseForm"
end select
end sub
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: [Solved] Cancel insert row

Post by MTP »

Hi RPG - thanks for the code snippet and the links to the interfaces, that's neat to be able to control error checking at that level. But I did try using the UndoRecordChanges command (I assigned that Action from a button's property window) and had the problem that (at least in my form) it changed two or three rows and not just one row! I think it calls the command refreshRow which the api documentation says:
The SDBC driver may actually refresh multiple rows at once if the fetch size is greater than one.
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: [Solved] Cancel insert row

Post by RPG »

Hello

I have the idea I did never used for me own refreshrow. When I want do such things I alway use the navigation toolbar or navigation control.

Using the standards in OOo is for me also the reason to find such information as I point earlier in this thread.

I can not tell any thing about refreshrow for more records: it is aoutside my knowledge. As far I knew OOo works only on one record at the time.

Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
Post Reply