Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Session/Macro prompts for local login, ignoring session on server

Status
Not open for further replies.

downwitchyobadself

Programmer
Aug 1, 2001
159
US
Using VBA, I'm running an Accpac macro that spits out an FR report, using code like so

Set MyFRReport = CreateObject("AccpacGL9100.AccpacMacro")
With MyFRReport
.CmdFRSelect strSourceFullFile
'blah blah set properties blah blah
.CmdFRPrintEx2 glnkComp, "file", 1, mstrDestinationPath, strDestFileName, 0
End With

once the session is properly logged (glnkComp is the company file link). On a fresh Windows login, unless a Sage company file is open, I receive a prompt, noting as Server <local machine>, which is wrong, and has nothing to do with the session I opened.

Once I reenter login data manually, it connects and processes properly. The session and company links are definitely open in VBA this entire time.

Also, as soon as Accpac has been opened and closed manually via the interface one time, this stops, i.e. something is happening to instantiate a connection to the proper application server. (It also doesn't happen if a company file is open in Accpac, though just the UI open with no file will cause the prompt.)

How do I instantiate this myself in VBA before executing the Accpac macro?

Thanks in advance for your help.
 
As long as you're using VBA, you can't instantiate, the login is automatci. Can you switch to VB?
 
Can you show me a snippet of VB code that illustrates what you mean? I've never run into a limitation before.
 
Something like this:

Set Session = AccpacCOMAPI.AccpacSession
Session.Init "", "AS", "AS1000", "53A"
Session.Open "ADMIN", "admin", "GOLDAT", Date, 0, ""
If Session.IsOpened Then
Set mDBLinkSysRW = Session.OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)
End If

 
That's pretty similar to my code--it's not a VBA vs. VB difference anyway. I do notice a difference in your choice of ProgramName argument. Would that perhaps help? I don't know what that argument signifies.

gses.Init ObjectHandle:="", _
AppID:="AS", _
ProgramName:="AS9031", _
AppVersion:="54A"

gses.Open UserIdentifier:=pstrUID, _
Password:=StrConv(pstrPWD, vbUpperCase), _
Database:=pstrDatabase, _
SessionDate:=Date, _
Flags:=0, _
Reserved:=""

apcOpenSession = gses.IsOpened

Set glnkComp = gses.OpenDBLink(pLinkType, DBLINK_FLG_READWRITE)
 
It might. I've been using "AS", "AS1000", "53A" for years, I never though of another way. Though, on the Accpac VBA forum, someone said this should be used:

session.Init "", "XY", "XY0001", "54A"

because XY is reserved for macros.
 
No, using those parameters doesn't change anything.

Frustrating--I don't understand how this code can successfully log in for all other purposes except to run a macro.

Is there something else I can do to read the state of the session that might tell me why it's failing?
 
I pulled this from a post from Greytrix:

Code:
Dim son As New AccpacSignonManager.AccpacSignonMgr
Dim sid As Long

Use following code to open and register the session...

Set Session = AccpacCOMAPI.AccpacSession
Session.Init "", "AS", "AS1000", "52A"
Session.Open "ADMIN", "ADMIN", "SAMINC", Date, 0, ""

If Session.IsOpened = True Then
'sid = son.RegisterSignon(UserID, password, orgid, orgdesc, Date)
sid = son.RegisterSignon("ADMIN", "ADMIN", "SAMINC", "SAMINC", Date)
Set mDBLinkCmpRW = Session.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
End If 
 PrintFinReport

Session.Close
Set Session = Nothing

End Sub

Sub PrintFinReport()
Dim GLFRRPT As Object
Set GLFRRPT = CreateObject("AccpacGL9100.AccpacMacro")

GLFRRPT.CmdFRSelect "C:\Accpac\ACCPAC52\GL52A\ENG\quikinc1.xls"
GLFRRPT.Year "2010" ' Year is YYYY
GLFRRPT.Period "12" ' Period is 1 - 13

' ngStatus = CmdFRPrintEx( AccpacDBLink, sgPrintType, ngNumCopies, sgPrintDirectory, sgPrintFile, nFileFormat )
GLFRRPT.CmdFRPrintEx mDBLinkCmpRW, "preview", 1, "", "", 0

Set GLFRRPT = Nothing
End Sub 
[\code]
 
Thanks for digging that up. I suspect that the SignonManager is the place to look, but I think this is just buggy behavior, and of course there's little documentation.

A couple more details:

- I can call the signon manager successfully but it doesn't change anything.

- If I use the .CmdFRPrintEx method, the template opens and closes with no output. If I use the .CmdFRPrintEx2 method, whether outputing to preview or a file, I am prompted a second time.
 
After further hair-pulling, testing AccpacSessionManager, AccpacSignonManager, etc. (why have one way of starting up when you can have 4?) I'm pretty sure that it comes down to a server name problem.

Once Accpac has been initialized, the COM Api "knows" where the server is and no longer asks. Prior to that, the server name is empty, so I assume that though I'm creating a session it's meaningless because "local".

I know from posts such as this one that a server name can be specified in managing the startup, but every version of the name and UNC combination I try just brings up a prompt to log in to a web server. Nothing I can find on this forum (virtually the only Accpac programming resource I know of on the web) tells me how to correctly set a network server name prior to logging in.

Is there somewhere else I could look? I've seen a few references to "the other VBA forum"...
 
Ah I see. Of a piece with Sage's ingeniously developer-friendly business model, perfect for the year 1992!

Is there a way to specify a server name simply? Nothing I try wants to work, and yet it's somehow getting set by Accpac once the UI initializes, thus getting rid of a prompt I'm very tired of seeing.
 
I don't know, I've only been coding Accpac VB macros for 8 years, and I've never had to do it.
 
Let me try a different question then. If you want simple report data available through, say, the Financial Reporter, in a usable format--i.e. rows & columns--without writing direct procs against backend databases and reinventing that wheel, and without user intervention, what do you do?

I'd imagine that with your experience you've come across a problem like this in Accpac, as I have needed similar functionality often in my 12 years of coding across a range of applications, developer-friendly and otherwise. It's been a long time since I was stumped by a login, so maybe I'm just going about it wrong.
 
Have you thought about simply running the macro from within Accpac? That's what all my clients do.
 
I would, but because it's a matter of multiple companies and a standalone application alongside it, the simplest would be to automate.

Thanks for your help though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top