Macro - Order Sub routine

Hi,

I want to add a macro to a button.
The code looks like this:

Sub GetID()
....
End Sub

SUB FormChange( sFormName )
...
End Sub

Sub OpenFormAtRecord()
...
End Sub

When I want to attach the macro to the button I see:

image description

Pushing the button returns an error. I guess because the order in the macro is wrong.
Bug? I’m doing something wrong?

Thanks

(Slightly edited for better readability by @Lupp)

Only you see the error. I don’t understand why not you show it.

The order in macros not is important.

Some more info since I can reproduce this on Mac and Linux.
This is the file I’m working on.
PassFormData.odb

Delete the macro from the button and add it again. There I see the wrong order, but it seems not important.
Running it again shows this error.

After I reboot my computer it works again. But changing the macro, there is the error again.
Very strange.

Hello,

Please do not use an answer to post additional information. It belongs as either a part of original question (just edit your question) or as a comment.

You can answer your own question but you post simply gives others looking for a similar answer incorrect information - no real answer.

Please delete this and post properly.

You didn’t think about the question - what parameter will the pressed button pass to your procedure? Put a breakpoint before the error line and see the contents of the sFormName variable. This is an object, a rather complex structure. You are trying to assign this complex value to a variable of a primitive type (string). Of course, BASIC is outraged

ObjectInDebugger

Hello,

You may want to review some of the documentation (especially on macros) posted here → To learn LibreOffice Base are there introductions or tutorials?.

When viewing libraries, there is no such thing as a sequence of macros. Your original question actually displays three different macros. They are listed in the Selector in Alpha sequence but has no relevance as to the sequence they were entered into the library.

The Execute action event of the push button should be attached to the GetID() event. GetID() in turn calls the FormChange( sFormName ) sub. The other Sub Sub OpenFormAtRecord(), is supposed to be attached to the second form.

The original post where you got this sample from ( what code do I need in a Base macro to access a field in highlighted row in a datasheet
) does mention h three different routines.

Also there is yet another (albeit more complex) version posted here → Base macro that opens a new/clean record in another form which does not use global variables.

Also, there can be many different macros stored in a library and few if any actually being used. In fact, none need to be used. The library is simply a storage area for macros. When you want to use one it is typically connected to an event. This event can be for a control, a form, the application and other things in other modules.

Thanks Ratslinger. I’ll try to move my post to the original question.

I’m still working on this invoice system:
Base Print Button

The idea is to create an overview of all invoices, select one, push a button to go to that invoice.
An overview was easy to setup. But a button to go to the selected invoice doesn’t work.

I just learned how to attach the subroutine OpenFormAtRecord().
I had no idea how this was done. One step further to reach my goal.

@TrippleDelta,

If you continue to have a problem, ask a new question and include a sample of what you have. Include any macros you are using. I don’t imagine, based on your comment, that this is any major undertaking and hope I can be of help.