Running a simple query from a macro

I created a simple query.
I’d like to imbed it in a macro that I can call from a button in a form.
I created a macro containing the query based on an LibreOffice example.
When I run the macro, I get a “Variable not found” for the line that starts “oConn”, yet oConn is clearly defined.
Also, I may not have the correct number of quotation marks in my SQL_string string - I’m learning.
The macro code is shown below.
What am I doing wrong?
Thanks

REM routine to display the highest WO#
Sub Last_WO
Dim oConn as Object
Dim SQL_string as String
Dim oQuery as Object
oConn = ThisDatabaseDocument.DataSource.getConnection("","")
SQL_string = “SELECT MAX( ““WO#”” ) FROM ““OHA_DB-WO-New”””
oQuery = oConn.createStatement()
oQuery.executeQuery(SQL_string)
End Sub

This macro is designed to start from the Base-GUI. Did you try to start it directly in macro editor? Then it wouldn’t know anything about ThisDatabaseDocument.