Solved

Oracle Connection Passing to functions in MSAccess VBA

Posted on 2011-09-28
3
570 Views
Last Modified: 2012-06-22
I am running several functions that connect to an oracle db and run sql. I am trying to figure out how to open the ODBC connection to oracle once, and pass it to each of the functions that need to run sql on the oracle db.  Currently I am establishing the connection in each function, causing the user to need to enter a password with each new connection.

Thanks for any help,
Lynn
Sub RunReport(reportType As String, sTime As Variant)

Dim strTime As Variant

strTime = sTime
    
      If reportType = "Terminating" Then
    
        
      ' Pass ACSCon
          'Get terminating accounts from ACCOUNTS
          Call GetACSAccounts(strACSConnectionACS(strServerName))
         
         'Get Terminating dates from TRANS
          Call GetTRANS(strACSConnectionACS(strServerName))
          
        ' Pulling TRAN names of tranDate userid
          Call GetTranNames(strACSConnectionACS(strServerName))
      
      Else
         
         'Get exceptions accounts from ACCOUNTS
          Call GetACSExceptions(strACSConnectionACS(strServerName))
      
      End If

    'Update Regions
    Call getRegions(reportType)
    
    'get user filter selections on form
    Call GetUserFilter(reportType, strTime)

End Sub



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Procedure:   GetACSAccounts
'
' Parameters:
'           strConnection - The ACS Oracle database Connection string
'
' PreConditions:
'           Requires that table [tblAccount] resides in database. ACS database records
'           are inserted into tblAccount.
'
' PostCondition:
'           Records from ACS tables are inserted into tblAccount
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Sub GetACSAccounts(strACSConnectionACS As String)

    Dim ACSCon As New ADODB.Connection
    Dim ACSrs As New ADODB.Recordset
    Dim strSQL As String
    
    varReturn = SysCmd(acSysCmdSetStatus, "Termination Report - Please wait...pulling ACS Account data")
    
    'clear table for new report data
    DoCmd.SetWarnings False
    DoCmd.runSQL ("DELETE tblAccount.* FROM tblAccount")
    DoCmd.SetWarnings True
    
    strSQL = "SELECT"
	‘big bunches of sql here....

    ACSCon = strACSConnectionACS
    ACSCon.Open
    ACSrs.CursorLocation = adUseClient
    
    ACSrs.Open strSQL, ACSCon, adOpenStatic, adLockReadOnly
    Set ACSCon = Nothing
    
    If Not ACSrs.BOF And Not ACSrs.EOF Then
        ACSrs.MoveFirst
        varReturn = SysCmd(acSysCmdSetStatus, "Termination Report - Please wait...inserting records into local table")
             
        Do Until ACSrs.EOF
            
            Call InsertAccount(ACSrs.Fields("InternalAccountNumber"), ACSrs.Fields("AccountKey"), _
            ACSrs.Fields("AccountSiteKey"), ACSrs.Fields("AccountShortName"), _
            ACSrs.Fields("AccountManagerKey"), ACSrs.Fields("AccountManagerFirstName"), _
            ACSrs.Fields("AccountManagerLastName"), ACSrs.Fields("AccountTFMKey"), ACSrs.Fields("TFMFirstName"), _
            ACSrs.Fields("TFMLastName"), ACSrs.Fields("AccountTrustReviewKey"), ACSrs.Fields("TrustReviewFirstName"), _
            ACSrs.Fields("TrustReviewLastName"), _
            ACSrs.Fields("TerminationFirstName"), ACSrs.Fields("TerminationLastName"), ACSrs.Fields("AccountStatus"), _
            ACSrs.Fields("AccountCondition"), _
            ACSrs.Fields("AccTermDate"), ACSrs.Fields("TermReason"), _
            ACSrs.Fields("ACTIVETICKLERCOUNT"), ACSrs.Fields("UNRELEASEDTICKLERS"))
            
         ACSrs.MoveNext
        Loop
    End If
    
     ACSCon.Close
    
    Set ACSCon = Nothing
    Set ACSrs = Nothing
    varReturn = SysCmd(acSysCmdSetStatus, "Termination Report - Done pulling ACS Account data")
End Sub

Open in new window

0
Comment
Question by:Lambel
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 500 total points
ID: 36794880
This is how I do it in SQL Server .... Oracle will probably use the same concept.  You just need to find the format of the Oracle connection string.  

Basically in Access you will open a QueryDef for your SQL Query and set the connection string as shown below.

Dim qdef As QueryDef
Dim StrSQLConn as String
Set qdef = CurrentDb.QueryDefs("YourQueryNameHere")

strSQLConn = "ODBC;Driver={SQL Server};Server=SSSSS;Database=DDDDD;Uid=UUUUU;Pwd=PPPPP;"

qdef.Connect = strSQLConn
qdef.Close

Then run your query.

ET
0
 

Author Closing Comment

by:Lambel
ID: 36817599
Thanks, this got me on the right track.
Lynn
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 36817655
Appreciate the points....

ET
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now