Avoiding a crash with storing 2 writer files based on database data

Hi folks,

I am desperate. I am a translator. I have a database of translation jobs, I made myself a macro to generate two writer files from templates. The filenames are generated from data in a database. One file is just opened and stored under a new name, in the other I make some changes. In the first half of last year, until I updated Libreoffice to the latest version, the macro worked (some parts of the window went black, but LO was willing to cooperate). Now I am getting crashes (the file is stored, but every time I generate the files, I have to restart LO). I think I must have done something wrong, but I am stuck. Please, have a look. If this is not the way to go, how to achieve the goal?

Thanks in advance.

Here goes the macro, activated by a button in a form:

Sub GenerateFiles
	Dim Doc As Object
	Dim DocB As Object
	Dim oDoc As Object
	Dim oForms As Object
	Dim oForm As Object
	Dim GeneratorFormName As String
	Dim SourcePath As String
	Dim TranslationSourceFileUrl As String
	Dim FormulaSourceFileUrl As String
	Dim TranslationTargetFileUrl As String
	Dim FormulaTargetFileUrl As String
	Dim TranslationHeaderString As String
	Dim SKFormulaString As String
	Dim HUFormulaString As String
	Dim YearString As String
	
	Dim Dummy() 'An empty array of PropertyValues
	Dim Dummy2() 'An empty array of PropertyValues
	Dim DummyB() 'An empty array of PropertyVal.ues
	Dim DummyB2() 'An empty array of PropertyValues
	Dim TextFieldEnum As Object
	Dim TextField As Object
	
	Dim oProps	as object
  	Dim oDocProps	as object
  	dim s as string
  	
  	UpdateFileNames() 'this updates TranslationFileNameField
  	
  	GeneratorFormName = "GeneratorForm"
  	SourcePath = "file:///z:/pecset/2026/"
	FormulaSourceFileUrl = SourcePath & "formulaSource.ott"
	YearString = "/2026"
  	
  	oForms = ThisComponent.DrawPage.Forms
	if oForms.hasByName(GeneratorFormName) then
		oForm = oForms.getByName(GeneratorFormName)
		
		if oForm.getByName("FromSlovakToHungarianField").getCurrentValue() then
			TranslationSourceFileUrl = SourcePath & "translationSourceHU.ott"
			SKFormulaString = "z jazyka slovenského do jazyka maďarského"
			HUFormulaString = "szlovák nyelvről magyar nyelvre"
		else
			TranslationSourceFileUrl = SourcePath & "translationSourceSK.ott"
			SKFormulaString = "z jazyka maďarského do jazyka slovenského"
			HUFormulaString = "magyar nyelvről szlovák nyelvre"
		end if
	
		REM translation file part
		
		REM load template and save new document as set name
		Doc = StarDesktop.LoadComponentFromURL(TranslationSourceFileUrl, "_default", 0, Dummy)
		TranslationTargetFileUrl = oForm.getByName("TranslationFileNameField").getCurrentValue()
		TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,"/","-")
		TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,"\","-")
		TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,":","-")
		TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,";","-")
		TranslationTargetFileUrl = SourcePath & TranslationTargetFileUrl
	REM	MsgBox "Translation part:" & TranslationTargetFileUrl
		Doc.storeAsURL(TranslationTargetFileUrl, Dummy2)
		
		REM formula file part
		REM MsgBox "Formula"
		REM load template
		DocB = StarDesktop.LoadComponentFromURL(FormulaSourceFileUrl, "_default", 0, DummyB)
		
		REM set values
		oDocProps = DocB.getDocumentProperties()
		oProps = oDocProps.UserDefinedProperties
	REM	MsgBox oProps.dbg_properties
	REM	MsgBox oProps.dbg_methods
		oProps.setPropertyValue("Copies",			oForm.getByName("CopiesField").getCurrentValue())
		oProps.setPropertyValue("CustomerAddress", 	oForm.getByName("ClientAddressField").getCurrentValue())
		oProps.setPropertyValue("CustomerNameHU",	oForm.getByName("ClientNameHUField").getCurrentValue())
		oProps.setPropertyValue("CustomerNameSK",	oForm.getByName("ClientNameField").getCurrentValue())
		oProps.setPropertyValue("DateOfExecution", 	oForm.getByName("ExecutionDateField").getCurrentValue())
		oProps.setPropertyValue("DirectionHU", 		HUFormulaString)
		oProps.setPropertyValue("DirectionSK", 		SKFormulaString)
		oProps.setPropertyValue("DocID",			oForm.getByName("JobIDField").getCurrentValue())
		oProps.setPropertyValue("DocNumber",		oForm.getByName("JobNumberField").getCurrentValue() & YearString)
		oProps.setPropertyValue("OrderID",			oForm.getByName("CaseIDField").getCurrentValue())
		oProps.setPropertyValue("PagesOriginal",	oForm.getByName("PagesOriginalField").getCurrentValue())
		oProps.setPropertyValue("PagesTranslation",	oForm.getByName("PagesTranslationField").getCurrentValue())
		oProps.setPropertyValue("TitleFixedHU",		oForm.getByName("SubjectFixedPartHUField").getCurrentValue())
		oProps.setPropertyValue("TitleFixedSK",		oForm.getByName("SubjectFixedPartSKField").getCurrentValue())
		oProps.setPropertyValue("TitleVariable",	oForm.getByName("SubjectVariablePartField").getCurrentValue())
	
		REM store file
		FormulaTargetFileUrl = oForm.getByName("TranslationFileNameField").getCurrentValue()
		FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,"/","-")
		FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,"\","-")
		FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,":","-")
		FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,";","-")
		FormulaTargetFileUrl = SourcePath & "formula/formula - " & FormulaTargetFileUrl
		DocB.storeAsURL(FormulaTargetFileUrl, DummyB2)
	endif
End Sub

If the bug appears when changing the version of LO and nothing else it would be a bug of the current LO-version. Try to reduce all the content of the macro code to the code, which only creates the file and reproduces the buggy behavior. Upload a file with the macro code here so other people could test.
If your system is Windows might be it is a bug like this: https://bugs.documentfoundation.org/show_bug.cgi?id=169876
.
Missing the system and the version of LO here. LO-version here is
Version: 25.8.4.2 (X86_64)
Build ID: 290daaa01b999472f0c7a3890eb6a550fd74c6df
CPU threads: 6; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded

My bad. Sorry. Here comes the info and a test sample (
test.zip (67.3 KB) - unzip into c:\temp, the macro in the odb file expects the contents of the file to be located in c:\temp\test).

version data:
Version: 26.2.0.3 (X86_64)
Build ID: 620(Build:3)
CPU threads: 16; OS: Windows 11 X86_64 (build 26100); UI render: Skia/Raster; VCL: win
Locale: sk-SK (sk_SK); UI: sk-SK
Calc: CL threaded

I tried to run it on another machine. First, it worked without crashing, so I thought it was some software conflict in my desktop, but then it just went crashing on my laptop, too.

The macro seems to open the first file and then crashes on the second. I tried to close the files in the macro, but that didn’t help either. I am not sure whether it is just the thing that it doesn’t like setting user defined parameters programmatically or there is something I am not aware of…

Thanks for looking into it.

You have installed the newest version of LO. If you use LO for work you better install a version, which won’t support the newest features. LO 25.8.4.2 or newer is still available. I would install one of this versions.
.
Tested the database with
Version: 25.8.4.2 (X86_64)
Build ID: 290daaa01b999472f0c7a3890eb6a550fd74c6df
CPU threads: 6; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded

Both files will be created without any problem.

Same result with
Version: 26.2.0.3 (X86_64)
Build ID: afbbd0df0edb6d40b450b0337ac646b0913a760c
CPU threads: 6; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded

Hi, I followed your advice and went back to this:

Version: 7.6.7.2 (X86_64) / LibreOffice Community
Build ID: dd47e4b30cb7dab30588d6c79c651f218165e3c5
CPU threads: 16; OS: Windows 10.0 Build 26100; UI render: Skia/Raster; VCL: win
Locale: sk-SK (sk_SK); UI: sk-SK
Calc: CL threaded

I ran a VMWare image of Linux to see if it worked - it did, too. I still don’t see the problem source, but this workaround is good enough.

Thanks.

Z.