problem running SQL from Basic [closed]

asked 2014-07-08 10:19:33 +0100

allanoptical gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2016-02-28 22:00:27.012450

Comments

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.

Regina gravatar imageRegina ( 2014-07-08 16:30:49 +0100 )edit

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

Alex Thurgood gravatar imageAlex Thurgood ( 2014-07-18 10:43:32 +0100 )edit