How are Base subforms named in LO basic?

I am trying to edit a small macro that was kindly written for me by ratslinger in response to an inquirey I made regarding putting macro text in a Base form textbox. Since I have no way to contact him directly, I’m relegated to asking my question in the forums.

I’m a total noob at LO basic, so try not to laugh too hard. The macro is embedded in a Base form named “Patient Data”. I need the macro to access a sub form named “Chief Complaint” instead of the main form “Patient Data”. The code I’m trying to edit follows:

REM ***** BASIC *****
Sub ShowText(answer)

Dim oForm As Object
Dim oField As Object

oForm = ThisComponent.Drawpage.Forms.getByName("Patient Data") 

oField = oForm.getByName("test") 

oField.text = oField.text & Chr(13)  + Answer 

End Sub

How do I pass the subform’s name to the getByName function to access the subform instead of the main form? I’ve not been able to find the naming convention for subforms in LO via Googling.

Thanks, and I hope ratslinger doesn’t mind me posting his code.

docbda

Since you already have the form “Patient Data” use

oSubForm = oForm.getByName("Chief Complaint") 

just as you would to get other controls. Use oSubForm to get at controls on the sub form.

BTW - any code placed here is not proprietary. It’s available to anyone.

I got it to work! I think I’m done pestering you for a while. Thank you for your patience and kind assistance. :smiley: I didn’t think you would mind me posting a small snippet of your code. I just didn’t know what the proper etiquette was in that regard.
Best,
docbda

I have one final twist that I need to address. There are multiple text boxes in the form that I am designing. I need the text generated by the macro to be inserted into the text box that has focus at the time the macro is called. I’ve tried using “oField = oSubForm.getCurrentController()” instead of “oField = oSubForm.getByName(“test”)”, which was the closest thing I could find find to a solution after a couple hours of research with no luck.

Is there a function that will return the identity of the textbox that holds focus so that the name of the textbox can be assigned to a variable?

Please understand, this is off topic and should be asked in a new question. Also, provide as much information as possible such as what is triggering the macro, the textbox or something else. If something else, how does the textbox have focus?

Whoops, sorry about that. Kinda new to the whole forum thing. I did ask this as a new question in addition to this comment, however. I won’t do that again in the future. I’ll also ammend my question to address the issues you have brought to my attention. Thanks for the heads up.