Function Sequence Error that resolves if I go into design mode and back out, but comes back everytime I open this Calc document

I cannot figure out why every time I open my calc document, this code throws a Function Sequence Error when called. Then the error resolves if I switch to design mode and back, and stays resolved unless i quit and reopen the document. But I need this to work without doing that so other people can use it!

The form in question is a reference to a single line of a table, it exists, is modifiable. It is defined and called and loaded before the line that throws the error. Pasting the code below, with a note on the line that throws the error.

Edited to say: It is assigned to Sheet Event > Activate Document, so it is called when I navigate to this sheet, but tested on other event as suggested, and still gets the error.

Sub LoadContactPage

Dim oSheet, oForm, oListB, oSubform As Object, nID As Integer
oSheet = ThisComponent.Sheets.getByName(“Contact”)
oForm = oSheet.getDrawpage().getForms().getByName(“Form”) ’ table tLookup, Key=2
oSubform = oForm.getByName(“Info”) ’ table tMember, linked by ID
oForm.reload()
oListB = oForm.getByName(“LBGroup”)
oListB.refresh()
oForm.reload()
nGrp = 0
sName = “”
nID = oForm.getInt(4) 'why does this get caught up on load??? Function sequence error???
If nID > 0 Then
nGrp = oSubform.getInt(4)
End If
sGroup = "Home Group: " & GetGrpWTwn(nGrp)
'show HG
oSheet.getCellByPosition(3, 6).setString(sGroup)

'set selected cell
ThisComponent.CurrentController.select( oSheet.getCellByPosition(0, 0) )
End Sub

Please upload your file containing the specified macro. Before uploading, you can delete confidential data and anything irrelevant to the issue.

Thank you for the reply, it will take some time for me to do this, it’s attached to a database that is confidential.

The appropriate event to use should be View created, imo.

Why? That’s a document wide event, I need this to run when a specific sheet is made the active sheet.

Why why?
(I’m not the guru, but…)
Activate document is the event thrown when the document is activated. (View created should follow a few ms later.)
There isn’t an event like Activate sheet. Your case needs to be treated under Selection changed.
This isn’t exactly simple (and even a bit buggy), imo.

I don’t use self-made listeners, but you may get something from subchapter 14.4 of Andrew Pitonyak’s “Useful Macro Information”.

See also Calc Sheet Activate event? - #3 by jfn.

That thread suggests sheet event Activate Document is effectively Activate sheet, which is true in my experience. Regardless, I tried your suggestions just for kicks and it doesn’t help solve the problem.

As I already told you, I don’t use this kind of listeners. However, @jfn and myself both tell

Ipointed you to the accepted solution by @jfn, not to a comment by @vib.

  • no there’s currently no such event as Sheet change that could be specified in the document events. You’ll have to set a listener for that.

What comes next to Sheet changed is Selection changed. There are lots of complications. If you found an error in the quoted post and code, you should post to that question, and probably you get a useful answer by the Qustioner who accepted the answer as solution or by @vib who wrote the code.

How so? Your code was based on that assumption - and failed.

(I’m out now.)

You’re quoting the person in the thread (@ vib) who was then told they are wrong. Keep reading. And the sheet change comments don’t apply because that is their problem not mine. And my code isn’t based on that assumption, and your suggestion didn’t change anything, I did try it. Peace out.