File corrupted in Libreoffice Base 4.1.1 when using macros

Hi,

I have this fairly complicated database and all was going well during its development, until some two weeks ago, when Base started saving the files with 0 to 50kb completely corrupted (its size is, with some records, about 1.2 mb normally).
Fortunatelly I had backups I made during the process of getting it working and today I found a very odd cause (or trigger for the bug).

I suck at writing macros, so, as a lot of people, I usually search the web for a macro that does what I need. Whenever I use these simple macros bellow, Base starts misbehaving again. I tested this in Windows and in Ubuntu 13.04. When I erase these macros, the save function works normally… Any clue why?

REM  *****  BASIC  *****

sub abrir_TEnt
const sNewDocumentName="TENT"
oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
end sub

sub abrir_TPes
const sNewDocumentName="TPES"
oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
end sub

sub abrir_IX
const sNewDocumentName="IXTE"
oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
end sub

sub abrir_NX
const sNewDocumentName="NX"
oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
end sub

sub abrir_CasX
const sNewDocumentName="CASX"
oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
end sub



REM  *****  BASIC  *****
' You need two controls in your form(document). They must be in the same form(as in navigator).
' One control is a text control and contains the pathname or url to the file.
' The second control is a button.
' The action is bound to the first event of the button control: Before commencing. ' Name before OOo3.2
' The name is new in OOo3.2 and later : Approve action
' The function can be aborted when the files does not exist.
' You have also change the properties of the button control.
' The action is :Open document/webpage.
' The small macro move the field value from the textbox to the button control url
function openurl(oEv as object)
' 
   dim oForm,oTextBox
   oForm=oEv.source.model.parent
   oTextBox=oForm.getbyname("SubForm")
   if FileExists ( oTextBox.text) then
      oEv.source.model.targeturl=oTextBox.text
      openur=true ' Do the programm when the file exists
      else 
      openurl=false ' The file does not exist and do nothing
   end if
   'print  convertfromurl(oTextBox.text)
End function


Sub Macro1

End Sub

I think it’s just a coincidence. File spoiled due to the large size. There is no apparent reason for the accident in the text of macro