Ask Your Question

# Libre Base button to open form from specific field

Hi all, newbie here. I have been through I think the majority of the solutions offered for this. I did have a solution but now it is not working and throwing up the following error. Error #1501 (No active connection to a database found) occurred in a call to function 'Forms' I have probably made some silly mistake. The basis of the macro is from another question.

Sub OpenForm ()
Dim prop(1) as New com.sun.star.beans.PropertyValue
forms=ThisComponent.Parent.getFormDocuments()
conn=ThisComponent.Parent.DataSource.getConnection("","")
prop(0).Name="ActiveConnection"
prop(0).Value=conn
prop(1).Name="OpenMode"
prop(1).Value="open"

oStartDoc = ThisComponent
oStartForm = oStartDoc.drawpage.forms.MainForm
i = oStartForm.columns.ProtectionID.getInt

oNewDoc = forms.loadComponentFromURL("Protection","_blank",0,prop())
oNewDocForm = oNewDoc.drawpage.forms.MainForm
wait 100
oNewDocForm.Filter = "ProtectionID ='" & i & "'"
oNewDocForm.ApplyFilter = True
oNewDocForm.Reload
End Sub


I would be very grateful for any help. Thank you.

Edited by @Ratslinger for readability (use preformatted text icon on toolbar)

edit retag close merge delete

## Comments

Hello,

Have tested posted code with my table names and all works without problem. Need sample (no personal or confidential info) to find where you problem lies.

Also you give little information. Where did you get the code from? What LO version being used (specific), OS, database used (connector where appropriate)? This should always be part of the information in a question.

Please edit the question to add the sample.

( 2020-06-08 18:21:08 +0200 )edit

Thank you so much for responding Ratslinger. I apologise for not giving enough information. Indeed the code did work yesterday but now it seems to have tripped and fallen. 1) I found the code here https://forum-test.openoffice.org/en/... 2) Libre Base Version: 6.3.4.2, Windows 10, SQL. 3) I have a mainform which is populated and I would simply like to open a different related table/form according to the value in a specific field on the mainform. They are both connected via ID keys. I have investigated other methods ie subforms etc. but I require a separate form to be retrieved. 4) The Error that appears is "Error #1501 (No active connection to a database found) occurred in a call to function 'Forms'". I probably have made a silly mistake.

( 2020-06-08 19:24:12 +0200 )edit

Thank you for the additional information but it is incomplete. Did ask for sample and see none posted in question. As stated, did test the code you pasted and it works. Opens selected record in another form. Need sample to determine what is wrong as it is not the code itself.

Edit:

Just noticed you noted SQL 3. This makes it hard to post a sample. Can you post a copy of the Base file? May be able to work with that. Again, the code works for me.

( 2020-06-08 19:50:10 +0200 )edit

Good morning, it is a bit complicated to put the working copy here but I have replicated the problem in this simple file. I have tried numerous different databases and the same error appears, therefore I can only presume that it is my set up. May I ask how do I upload the file? I have obviously missed a button somewhere. I do apologise.

( 2020-06-09 09:44:59 +0200 )edit

For future reference. Attaching a file. Edit question & use paperclip icon on toolbar in upper left. See -> How do I attach a file to my question/answer?

( 2020-06-09 17:33:44 +0200 )edit

## 1 Answer

Sort by » oldest newest most voted

Hi Ratslinger, thank you so much for all your help. Your confirmation that the code worked pushed me to look deeper into my set up. It was a bug I had to reboot several times, there was a hidden Libre Office file working in the background separate from Libre Base. Once everything connected to Libre Office was rebooted a couple of time the script worked. Thank you again for your time and experience.

more

## Stats

Asked: 2020-06-08 12:39:58 +0200

Seen: 30 times

Last updated: Jun 09