Application.LoginAs - kills add-in during execution

Hello,

We currently have an add-in that lets users send a doc to the BCA. The add-in is necessary because the doc is sent to the BCA with variables embedded in it that are used when the doc is run through a macro on the BCA at refresh-time.
At the moment if a user sends a report to the BCA, and then their ID gets revoked or deleted, the report will fail. This is not what we want.

My idea is to modify the add-in so that the doc is sent to the BCA using a generic ID which only we will know the PW to and which will never revoke or be deleted.

The trouble I’ve got is that as soon as I execute a Application.LoginAs from the VBA, all documents, including my .rea add-in, are closed!

This is my code so far:

Dim newSession As Application

Dim sFilename As String
sFilename = Format(Now, "ddmmyyyy_hhmm") & "SI.rep"

Application.Interactive = False
ActiveDocument.SaveAs "c:\" & sFilename
Application.Interactive = True

Set newSession = New Application
newSession.LoginAs "TestID", "pw", , "BOMain"
MsgBox "Code is still running"

The code never gets as far as the MsgBox :frowning:

Is there any way to change user mid-code execution? Or another way to use a different ID for automatically sending the report to the BCA?

TIA,

Robin.


RobinM :uk: (BOB member since 2003-02-25)

I have one theory. When instantiating a new session of BusObj, it has a nasty habit of OCCASIONALLY grabbing an existing instance. Sounds like that is what is happening in your case. It’s trying to log in the current instance again. This is how I code to get around that:

Dim BOApp As busobj.Application
Set BOApp = New busobj.Application
Do Until BOApp.Variables("BOUSER").Value = ""
    Set BOApp = New busobj.Application
Loop

BOUSER is empty in a TRULY new instance.

One other thought. I think the .LoginAs needs all four parameters filled in for it to be “silent.” Otherwise, it simply pops up the login box. I can’t remember if that is true for all of the parameters, but you may want to try this:

newSession.LoginAs "TestID", "pw", False, "BOMain"

Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Thanks Dwayne, that works a treat :slight_smile:

However I’ve now done my testing and realised that I was incorrect about user ID status affecting a BCA job. A user can change their password, revoke themselves or even be disabled; the report will still run. The only problem is if you delete the user, because then their associated BCA reports get deleted. This is all based on reports/universes using an embedded ID/PW, not passing the user’s authentication details to the database.

Still, good to know that my solution would have worked in VBA if I’d needed it… :?


RobinM :uk: (BOB member since 2003-02-25)

Glad it worked for you, even if it wasn’t needed.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)