We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question
0

Executing SQL Statements from Forms with macros

asked 2020-08-12 13:09:37 +0200

JustAsking gravatar image

updated 2020-08-12 15:49:57 +0200

Hello all,

I've been using some macros to automate certain SQL statements with the following code:

sub executeSQLcmd(SQLcmd as String)
      Dim oStatement As Object
      if IsNull(ThisComponent.CurrentController.ActiveConnection) then
       ThisComponent.CurrentController.connect
    endif
    oStatement = ThisComponent.CurrentController.ActiveConnection.createStatement()
    oStatement.execute(SQLcmd)
end sub

I've always used Tools > Macros > Execute to get the job done but I grew tired of this and tried to assign some buttons in a simple form to do the same but without success. The BASIC interpreter throws an exception at the line if IsNull(ThisComponent.CurrentController.ActiveConnection) then and says ActiveConnection is not found.

Perhaps there's no ActiveConnection to be found in a Form? If so, what's the better alternative to the class ThisComponent.CurrentController?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2020-08-12 17:36:55 +0200

Ratslinger gravatar image

Hello,

I run SQL from forms quite often. Here is one method:

if IsNull(Thisdatabasedocument.CurrentController.ActiveConnection) then
    Thisdatabasedocument.CurrentController.connect
endif
oStatement = Thisdatabasedocument.CurrentController.ActiveConnection.createStatement()

Here is another:

oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_INTERNAL_FORM_NAME")
oStatement = oForm.ActiveConnection.createStatement()
edit flag offensive delete link more

Comments

Both worked great! Thank you.

JustAsking gravatar imageJustAsking ( 2020-08-12 19:43:19 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-08-12 13:09:37 +0200

Seen: 80 times

Last updated: Aug 12 '20