Syntax Form Controls Base

Sorry for the confusion. This is my first post here. I am versed in Access and VBA. I am struggling getting the syntax correct to even do a basic msg box command to show the value of a control. I assume I am missing something very simple. Thanks for your help in advance

I get the following error:

I have also attached the Form Navigator:

Here is the code I am using:

Dim ofForm as object
Dim ocControl As Object
Docmd.OpenForm(“RE_Header2”)
set ofForm = Forms(“RE_Header2”)
ocControl = ofForm.Controls(“txtLeif”)
MsgBox ocControl.Value

(Edit: activated screenshots -AK)

I get the following error

Which one?

You want a working database? Delete all Basic modules and start all over with a normalized database.

Hello,

Certainly not too familiar with Access2Base. Tried it when switching from Access a few years ago. Decided to learn UNO API instead. Revisiting this I am glad at the direction taken.

With a bit of testing, got the code to work by using the Base form name and not the internal form name. Personally don’t understand this. Not certain how this would work if you had multiple internal forms as I use this quite often. Also, your OpenForm statement is to actually open a Base form and not to gain access to the existing form. Not certain that is what you actually wanted. Tested with code similar to yours (different names):

Dim ofForm as object
Dim ocControl As Object
set ofForm = Forms("USE_EXTERNAL_FORM_NAME")
ocControl = ofForm.Controls("txtLeif")
MsgBox ocControl.Value

Also as a test out of curiosity, tested with the control on a subform:

Dim ocDate As Object, vValue As Variant, sText As String
Dim ocSubform As Object, osfSubform As Object
Set ocSubform = Controls("USE_EXTERNAL_FORM_NAME", "USE_INTERNAL_SUBFORM_NAME") 
Set osfSubform = ocSubform.Form 
ocDate = osfSubform.Controls("myDateField")
sText = ocDate.Text
vValue = ocDate.Value
MsgBox sText & " - " & Day(vValue) & "/" & Month(vValue) & "/" & Year(vValue)

May try another time to investigate how to utilize multiple internal forms.

Edit 2019-10-02:

It is possible with Access2Base you are not loading the library and setting the connection:

If GlobalScope.BasicLibraries.hasByName("Access2Base") then
	GlobalScope.BasicLibraries.loadLibrary("Access2Base")
End If
Call Application.OpenConnection(ThisDatabaseDocument)

A routine of this type can be set when opening the document.

However, attached is a sample of macros using both Access2Base and Star Basic to display the contents of a text box. The single form has buttons to accomplish this.

Edit #2:

Modified sample to separate the loading and connection macro and added the closing connection macro. These were added to the .odb events under Tools->Customize on the Events tab:

Sample------- AccessVsBasic.odb

Thank you Ratslinger,
I tried your code and am still getting the same error. I will look at UNO API.
Best
Steve

@Steve_s1,

Without Access2Base, here is a sample to access a control:

dim oForm as Object
dim oField as Object
oForm = ThisComponent.Drawpage.Forms.getByName("RE_Header2") 'Get Form
oField = oForm.getByName("txtLeif")

If you continue to have problems, you can post a sample Base file in your edited question. Be glad to take a look.

Installed Open Office. Do I need to write the macros in Java?? Currently I am using the OPEN OFFICE BASIC in the organize macro tool bar. When I take your code, it chokes on “oForm = ThisComponent.Drawpage.Forms.getByName(“RE_Header2”) " with the error 'Propere or method not found: Drawpage”. I am sure that I am missing something basic, like not having an extension installed, or writing the macro in the wrong language…

Not certain why the move to OpenOffice as LO currently has more developers working on it.

To your question, code provided & the IDE is for Basic. Where are you executing the code from - the IDE or from the Form? Should be from the form. Again a sample may help to see what you are doing.

Have added sample in edited answer. And if you indeed have moved to OpenOffice, I believe to use Access2Base you first need to install the library. In LO it comes installed.

I tried both versions above. I can find the name of an integer field or memo field but not their value or text properties. Could you show a msgbox that displays the contents of oField in the pure Basic version here? I’ve tried .text, .text(), .getText(). It appears that the object retrieved is the model of the control in either the Access2Base or pure Basic versions because neither has the model property.

That is already in the sample in my answer. There are two buttons on the form - one to display with Access2Base and the other with StarBasic. Just re-tested & they both work. Just look at the code within the provided sample.

I’m running LO 7.1 on Windows. I can show oField.Name (which I already know since it’s what I used to create oField), but Basic complains that oField does not have Text or Value attributes. I also tried it on an integer field (the primary key). It does not complain that the Value attribute does not exist, but always returns 0, no matter what the actual value is. I tried both Print and msgbox, just to be sure I wasn’t tripping up on some other bug.

Your comment has no basis. Here is the Sub from the sample:

Sub StarBasicDisplay
    dim oForm as Object
    dim oField as Object
    oForm = ThisComponent.Drawpage.Forms.getByName("RE_Header2") 'Get Form
    oField = oForm.getByName("txtLeif")
    Print oField.Text
End Sub

and here is the result:

So what is the basis of your comment?

The table field is Text[Varchar] and the control is a text control. The return property is Text.

If you can show something different then do so. Please do not make claims without proper explanation and or samples.

My bad. It appears that the field I was interrogating was a multiselection field, made when I was first creating my first form. I created a text box and linked it to the same table field, and it works. Now to sort out the value property problem with an integer field. Maybe I also used an incorrect field type even though it seems to work otherwise. Seems to return NULL or Nothing. Thanks for the patient help.

Then look at → Get all selected items in a listbox?

Two birds with one stone - listbox selection and a dialog example! Thanks again.