Solved

Oracle Connection Passing to functions in MSAccess VBA

Posted on 2011-09-28
3
569 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
Comment Utility
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
Comment Utility
Thanks, this got me on the right track.
Lynn
0
 
LVL 19

Expert Comment

by:Eric Sherman
Comment Utility
Appreciate the points....

ET
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

10 Experts available now in Live!

Get 1:1 Help Now