Page 1 of 1

[Solved] Cancel insert row

Posted: Thu Jul 31, 2008 11:18 pm
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?

Re: Cancel insert row

Posted: Fri Aug 01, 2008 11:36 pm
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".

Re: [Solved] Cancel insert row

Posted: Sat Dec 27, 2014 11:54 pm
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!

Re: [Solved] Cancel insert row

Posted: Sun Dec 28, 2014 2:23 am
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

Re: [Solved] Cancel insert row

Posted: Sun Dec 28, 2014 5:58 pm
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.

Re: [Solved] Cancel insert row

Posted: Sun Dec 28, 2014 6:47 pm
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