Form filters in LibreOffice Basic

I need some help with an error.

I am trying to open and filter a form by pushing a push button on another
form.

The error is an: “Error 423: Property or method not found: Filter.”

Here is the code that generates the error:

  dim frm as object
  dim id as integer
  
  id = ThisComponent.Drawpage.Forms.getByName("MainForm").getByName("Id").Text
  frm = ThisDatabaseDocument.FormDocuments.getbyname("frmKingdom")
  frm.Filter = "('tblKingdom'.'Id' = " & id & ")"
  frm.open

The line that starts with “frm.Filter” is the one that causes the error. I
have tried putting the “frm.open” before the line with “frm.Filter”, but the
same error still occurred.

Any ideas?

Hello,

Have a few solutions. One is a global variable and the other is similar to yours. On the surface your problem appears to be mostly because the form is not opened first.

See the samples in my answer here → Base macro that opens a new/clean record in another form

PassFormDataWithNoGlobal.odb in edited section is what you most likely want

Edit:

Aside from the code in the sample to open the other form, your syntax for the filter in incorrect. Your table and field name need to be surrounded by quotes not apostrophes and quotes within quotes requires double quoting:

frm.Filter = "(""tblKingdom"".""Id"" = " & id & ")"