problem running SQL from Basic

Last month I asked how run an SQL file in Base and was given a very effective code segment that was a an effective solution.

The code runs perfectly when called from the Macro menu.

However I now would like to call it from a button. I have an empty form with just one button on it (others will follow) which has the subroutine attached to its “Pressed” event.

The code contains this snippet.

if IsNull(ThisComponent.CurrentController.ActiveConnection) then

 ThisComponent.CurrentController.connect

endif

When I run from the Macro menu, or single step from the Basic editor everything is fine.

When I run from the button the code runs as far as the snippet above and then gibe the error message BASIC runtime error.

“Property or method not found: ActiveConnection.”

Any suggestions as to what I should do please?

It is not clear, from where you call the macro. If you call it while the .odb document is active, then “ThisComponent” is a DataBaseDocument. If you call the macro while the form is active, then “ThisComponent” is a likely a TextDocument. You should set a breakpoint and look, what you are actually get by “ThisComponent”.

If you use an internal form, then you can get the associated .odb document using the parent property of the form.

You might find it easier with the Switchboard extension, but read this tutorial first.