Using the open database in your script
Brian Element
Forums
Sometimes you might want to use a script on an open IDEA file, the scripting language has a function to get the name of the current database, namely Client.CurrentDatabase(), the one problem with this is if there is no IDEA database open then the script will give you an error and stop. The way to get around this is to use the On Error Resume Next. So you try getting the current database, if the err.number is 0 then that means there was no error and a database is open, if you do get an error then you know that there is no open database and your filename is blank. Below is a piece of code that will do this. All my new scripts contain this and as I revisit my older scripts I am adding this.
Dim db As database
On Error Resume Next
Set db = Client.CurrentDatabase()
If err.number = 0 Then
sFilename = db.name
Else
sFilename = ""
End If
Set db = Nothing