List of Forms in database

Would like Base to list out all the forms in my current database. Tried chat GPT for hours with no results. Thanks.

Hello,
You can list with a short macro:

Option Explicit
Sub formList
  Dim oFormDocuments As Variant
  Dim nCount As Long
  Dim oFormObj As Variant
  Dim sNameList As String
  Dim x As Integer
  oFormDocuments = ThisDatabaseDocument.getFormDocuments()
  nCount = oFormDocuments.getCount()
  sNameList = ""
  for x = 0 to nCount -1
    oFormObj = oFormDocuments.getByIndex(x)
    sNameList = sNameList & chr(10) & oFormObj.Name
  next  
  MsgBox sNameList
End Sub

Works from Basic IDE:
Screenshot at 2023-02-23 17-13-37

or form:
Screenshot at 2023-02-23 17-13-13

Thank you for the quick response ! Seems to always get stuck at: oFormDocuments = ThisDatabaseDocument.getFormDocuments()

Saying that variable not set. Tried for hours with Chat GPT and always get the same errors.

Where are you executing the code from? What does your code look like? Copy of mine? You can see from my screens that the code has worked from IDE & form.

Sounds like that is the second time you have no help after hours of searching. Hardly seems worth the effort.
.
If you continue to have an issue, post a sample of the Base file.

Instead of asking some artificial idiot, you should learn first things first, e.g. about ThisDatabaseDocument and ThisComponent.

If your form documents are non-hierarchical (no form documents in folders):

msgbox join(ThisComponent.FormDocuments.ElementNames, ", ")

Just made a form with only a textbox and push button, saved it, then on the push button I assigned the Macro formList. When run from the push button on the form, nothing happens. When run in the Macro run, it comes up with BASIC runtime error.
Variable not defined. and highlights:
oFormDocuments = ThisDatabaseDocument.getFormDocuments()
I am using Using Version 7.5.0.3

You should be able to debug your own program. No idiotic bot will do that for you and we can’t. What do you expect the above code to do? Works for me doing nothing.

Sorry, was just trying to figure out why my copy is not accepting the code. Thought I would try the bot for newbie questions rather than bother this forum with simple queries. Have downloaded many videos and content from the web how to program this and it just won’t accept any code that it recieves.

The reason the question was so simple was that I am having problems with it not recognizing names of forms and figured just a simple print out the forms it sees would help.

@Corey
.
You should approach the actual problem (best with sample) and not how you think it may be solved. Actually saves time.
.
Here is a working sample of the code I posted → ListForms.odb (11.9 KB)

forms.odb (60.6 KB)

Thank you very much, your example works perfectly in your form. I put another button on your form and attached it to the same Macro and it worked too. I made another form with a button and attached it to the same Macro, comes up with the same error in Run Macro and nothing happens when I click the button on the form.

Thank you for your patience here, guess I am in over my head here.

@Corey
Can’t say it enough - Post a sample containing the error. Can’t do too much more without one. Surely you can see what a sample did for you visualization.

MyListForms.odb (10.5 KB)
Very sorry, didn’t know I could drop an attachment in here.

@Corey
It was my guess the macro is not in the document. You must have placed it under MyMacros and that will be an issue there. Take a look at the sample I posted and see where those macros are.

You may want to look at → ThisDatabaseDocument vs ThisComponent?

And documentation → LibreOffice Developer's Guide: Chapter 11 - LibreOffice Basic - The Document Foundation Wiki

I kept pasting into the MyFormsList Standard and it kept on putting it in the MyMacro section. Deleted it and retried many times. The way I am pasting it in is through the edit Macros on the tools menu. Would that be it ?

@Corey
You should look at the second link I provided.
You cannot place it in MyFormList Standard because you have not created a module there:

Screenshot at 2023-02-25 16-31-22

In the Image you can see my Base file with the code in Module1. You have no module in Standard to place code.

Go through the second link I gave you.

Thank you, will donate for all the time you have spent ! Have a great day.

1 Like

Thank you. All you guys there are great !

Thanks so much ! Making that module made everything work !