Existing form object not found

I am new to LO environment, and struggling with a very basic issue. I installed the latest version of LO [v5.3.5.2 (x64)]and using Base with integrated Access2Base (v1.6) for an application. I am trying to retrieve the values from other controls on a form when a combobox is activated. My macro is invoked, but I consistently see unknown form error when using the Forms(“name”) or getObject(“shorthand-name”) syntax. I have tried a few alternate expressions, but cannot seem to get beyond this. Sample code below.

By stepping through the Access2Base code, I can see the form name in the AllForms collection, but something downstream throws error. I have ensured the name of form and the search parameter are exactly the same, including case. Anyone have suggestions on what may be wrong?
Thanks in advance!

    SUB FindAvailableCampsites(Optional poEvent As Object)
    	DIM ocSiteName AS Object, odCheckIn AS Object, odCheckOut AS Object, ocSiteType AS object
    	DIM ofForm AS Object
    
REM  Trial of different syntax to access form name
    	Set ofForm = Application.Forms("NewCampingReservation")
    	
    	Set odCheckIn  = getObject("Forms!NewCampingReservation!txtCheckIn")
    END SUB

Hello @Spun69,

To access a control inside a Form Document, that Form Document must first be opened.

Please try the following:

SUB FindAvailableCampsites(Optional poEvent As Object)

	Dim oFormDocuments As Object
	oFormDocuments = ThisComponent.getFormDocuments()

	Dim oFormDocument As Object
	oFormDocument = oFormDocuments.getByHierarchicalName( "NewCampingReservation" )
	oFormDocument = oFormDocument.open

	Dim oForm As Object
	oForm = oFormDocument.DrawPage.Forms(0)

	Dim oControlModel As Object
	oControlModel = oForm.getByName( "txtCheckIn" )

	Dim oControl As Object
	oControl = ThisComponent.CurrentController.getControl( oControlModel )

END SUB

Have not used Access2Base except for some minor testing and forum answers so I won’t be able to give you much more info than what is in this answer. My belief is that you are trying to access controls on a form which you currently have opened and are working with.

First, I suppose you have already seen the Access2Base site (click here). In the section Tutorial (left column toward top) is a nice sample of TT Northwind DB containing a good deal of working code. One part I noticed dealing with a combo box:

Sub Update2ndCombo(poEvent As Object)
Dim ocCombo1 As Object, ocCombo2 As Object, sSQL As String
	Set ocCombo1 = Events(poEvent).Source
	Set ocCombo2 = ocCombo1.Parent.Controls("EmployeeName")
	sSQL = "SELECT DISTINCT [LastName] FROM [Employees] WHERE [Employees].[City]='" & ocCombo1.Value & "'"
	ocCombo2.RowSourceType = com.sun.star.form.ListSourceType.SQL
	ocCombo2.RowSource = sSQL
End Sub

Sub UpdateMainForm(poEvent As Object)
Dim ofForm As Object, ocCombo As Object, sSQL As String, lEmpID As Integer
	Set ocCombo = Events(poEvent).Source
	Set ofForm = ocCombo.Parent
	lEmpID = DLookup("[EmployeeID]", "[Employees]", "[LastName]='" & ocCombo.Value & "'")
	ofForm.Filter = "[EmployeeID]=" & lEmpID
	ofForm.FilterOn = True
End Sub

You can see in the first sub how the control which originated the event was obtained from poEvent and in the second sub ofForm was also gotten from poEvent.

Again, get the sample if you are going to stick with Access2Base.

If this answers your question please click on the :heavy_check_mark: (upper left area of answer).

Issue was due to mismatch between the external name of object (e.g. form name as seen in navigator) and the name of the object in property sheet. Once the names where updated to match, the script worked as expected.