Ask Your Question
0

Macro - Order Sub routine

asked 2020-05-23 18:00:42 +0100

Tripple Delta gravatar image

updated 2020-07-28 21:17:36 +0100

Alex Kemp gravatar image

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)

edit retag flag offensive close merge delete

Comments

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

The order in macros not is important.

mauricio gravatar imagemauricio ( 2020-05-23 18:35:46 +0100 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2020-05-23 20:02:08 +0100

Ratslinger gravatar image

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.

edit flag offensive delete link more

Comments

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.

Ratslinger gravatar imageRatslinger ( 2020-05-23 20:28:18 +0100 )edit

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.

Ratslinger gravatar imageRatslinger ( 2020-05-24 05:49:58 +0100 )edit

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.

Tripple Delta gravatar imageTripple Delta ( 2020-05-24 14:57:56 +0100 )edit

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

Tripple Delta gravatar imageTripple Delta ( 2020-05-24 15:52:09 +0100 )edit

@Tripple Delta,

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.

Ratslinger gravatar imageRatslinger ( 2020-05-24 18:51:52 +0100 )edit
0

answered 2020-05-23 18:55:01 +0100

Tripple Delta gravatar image

Some more info since I can reproduce this on Mac and Linux. This is the file I'm working on. C:\fakepath\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. image description

image description

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

edit flag offensive delete link more

Comments

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.

Ratslinger gravatar imageRatslinger ( 2020-05-23 19:53:11 +0100 )edit

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

JohnSUN gravatar imageJohnSUN ( 2020-05-23 20:11:23 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-05-23 18:00:42 +0100

Seen: 67 times

Last updated: May 23