The importddatabase statement needs the name of the open database and not the file name and path. If you don’t have the database name of the open database you want to import but only the actual file name, you could adjust that by stripping the file extension from the file name which should give you the database name. Here is that change made to your code:
I was starting to type a reply when Gary beat me to it. Thank you Gary!
However, please note that using arrayfirst( like that assumes that the filename doesn’t have any periods in the filename. A filename like a.b.c.pandb is perfectly legal, but won’t work with Gary’s code. Probably the best bet would be not to include the .pandb extension in the file variable in the first place, the opendatabase statement doesn’t need it. Then you could use
Also, in Panorama X you probably don’t need the folderpath( function. But that’s a whole other can of worms. See the Folder IDs section of the Files and Folders help page to open the can.