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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Macro Best Practice - Session Initialization

Status
Not open for further replies.

iwells

Programmer
Oct 2, 2012
284
CA
Hi,

In my first post I asked some fairly generic questions and received some deserved generic answers, but at this point I'd like to post some specific code for your analysis. The new organization I've joined doesn't have any existing modules in place, it appears as though they just copy/paste code from previous macros into new ones or copy the macro itself and edit it. Furthermore, there appears to be a lot of use of ADO.

1) Will I be correct in attempting to steer users away from ADO to AccPac views? The majority of the macros are for reports so I don't think there's any data editing happening. What other reasons might there be other than existing logic in the views to use the views over ADO. Keep in mind you're not selling me, but other users (I see the inherent advantages of the existing methods and objects in the ACCPACCOMAPI).

I'd like to create a module as a sort of best practice to be added to each report and here's what I've seen on the forum so far:

Code:
Option Explicit

Public sSession As AccpacCOMAPI.AccpacSession
Public mDBLinkSysRO As AccpacCOMAPI.AccpacDBLink
Public mDBLinkCmpRO As AccpacCOMAPI.AccpacDBLink

Private Sub Test()
    
    Set sSession = New AccpacCOMAPI.AccpacSession
    
    sSession.Init "", "XY", "XY1000", "56A"
    sSession.Open "ADMIN", "ADMIN", "CMPDAT", Date, 0, 0
    
    If sSession.IsOpened Then
        
     Set mDBLinkSysRO = sSession.OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READONLY)
     Set mDBLinkCmpRO = sSession.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READONLY)
    End If
End Sub
[code]

I've not included the .close, = nothing for the session and the error handler yet.

2) This is the beginning of a sample module I want to create for each new report. Is what I've posted above correct? My biggest concern is what happens if a user has multiple sessions open? Also in some people's posts I see the use of AccpacSessionManager and AccpacSession instead of the AccpacCOMAPI ... I'm curious of the differences here if any?

3) The organization has varying versions of Accpac (we're upgrading, but that's an on going project) and it isn't as simple as saying "update them" so I'm wondering if the .Init will fail on previous/later versions? Are there ways around this and related concerns to doing so?
 
Not to mention I handle all my .Closing in separate procedures.
 
The procedure you've posted jumps directly to the error handler and says error opening GL0030
 
Take out the New in:
Public DBLinkCmpRW As New AccpacCOMAPI.AccpacDBLink
Public GLPOST As New AccpacCOMAPI.AccpacView

Check the scope of the variables, you are declaring 2 public variables in 2 different places.
 
Is GL activated in the company? Check Help, System Information.
Is GL installed?
 
It is installed and there's data in the table ... I'm really perplexed
 
And to your other comment about New, that's done and I've fixed the scope to a Private Sub with all dim statements and that's the only Sub I'm calling.
 
Hmm ... AS views and tables work, not others. I'm logged in as ADMIN.

 
Go to Help, System Information, scroll down to GL, do a screen print and post it here.
 
My bad, AS0025 is a company view, I was thinking AS0003.

FWIW, why are you writing a macro to do a database dump?
 
Tuba,

It's a long post, but originally I was trying to export GL info (GLPOST specifically), but the example ettienne gave was for a database dump. AS works, GL does not.
 
Login to Accpac, open the company and then see if you can open any GL screens.
 
GL0018 doesn't open GL0030. GL0018 is a flat view. I realize you're not wanting to post code back but we can't help unless we can see the whole picture.

Post back the macro that Ettienne gave you that opens view GL0018. I just ran it and it worked for me.
 
Sorry, I was out sick for a few days. I reinstalled Accpac and now it works ... I'm relatively new to the company and I'm guessing the install had issues before I got the PC.

Sorry for the complaining and frustration, I was starting to get ill and clearly something that should have been working wasn't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top