I’m on Windows 10, running LO 7.0.6.2, and I’m using Base for a frontend on my MySQL database. In my macro (started by the Base form document “Adding Authorizations” opening), I have the line (which I got from a solution posted here by @RobertG .)
ThisDatabaseDocument.FormDocuments.getbyname("Adding Authorizations").close
I get the error message from that line
BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.WrappedTargetException
Message:
TargetException:
Type: com.sun.star.embed.StateChangeInProgressException
Message: .
I’m not sure if the WrappedTargetException is because I’m trying to close the form that’s just opening. Anyone know what the problem is and what I can do to fix it? Basically, The objective is to run a query about the current database user and based on the result, close the database form.
To give a little better context, This is part of my macro:
oSQLStatement = oDB.createStatement
sSQL = "select user()"
Result = oSQLStatement.executeQuery(sSQL)
Result.first
sUser = Result.getString(1)
'get the database user name by splitting off the @hostname
mUser = Split(sUser, "@")
'get the id number of the user
sSQL = "select id from Personnel where login = '" & mUser(0) & "'"
Result = oSQLStatement.executeQuery(sSQL)
Result.first
iUser = Result.getInt(1)
sSQL = "select count(id) from authorizations where authtype = 14 and personnel = " & iUser
Result = oSQLStatement.executeQuery(sSQL)
Result.First
If Result.getInt(1) = 0 Then 'Current user has not been authorized to grant authorizations. So Display message to that effect and close the Adding Authorizations form document
msgBox "You have not been authorized to grant authorizations! Please see the Laboratory Administrator."
wait 1000
ThisDataBaseDocument.FormDocuments.getbyname("Adding Authorizations").close
Exit Sub
End If
The reason I’m using the macro started by the form opening is because the unauthorized user could open the form directly from the main Base window.