Results 1 to 3 of 3

VBA addin - ODBC via ADO compared to DAO

Threaded View

  1. #1
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    VBA addin - ODBC via ADO compared to DAO

    I have a vba addin that was originally created in DAO format and it is really quick, problem is that this addin needs to be shared to a lot of ppl and we need to a lot of setup to get DAO to function correctly within Excel 2007, so I am trying to switch the addin to ADO. The speed in ADO is terrible compared to the DAO. The DAO does 4800 records in about 36 seconds and ADO is doing the same amount of records in 30 minutes.

    DAO setup:
    Option Explicit
    Dim systemname
    Dim sqlstatement
    Dim db As DAO.Database
    Dim wk As DAO.Workspace
    Dim myerror As Error
    Dim connStr
    Dim isopen As Boolean
    
    Sub openconnection()
    'assign systemname, sqlstatement and connection string
    
    If isopen = True Then
        Exit Sub
    End If
    
    systemname = "database"
    
    connStr = "ODBC;DRIVER={Client Access ODBC Driver (32-bit)};SYSTEM=" & systemname & _
        ";CMT=0;DBQ=QGPL;NAM=0;DFT=0;DSP=0;TFT=0;TSP=0;DEC=0;XDYNAM" & _
        "IC=0;RECBLOCK=0;BLOCKSIZE=8;SCROLLABLE=0;TRANSLATE=1;LAZYCLOSE=1;LIBVIEW=0;REMARKS=0;CONNTYPE=0;SORTTYPE=0;LANGUAGEID=ENU;SORTW" & _
        "EIGHT=0;PREFETCH=0;MGDSN=0;"
    
    'initialize database stuff
    Set wk = CreateWorkspace("", "", "", DAO.dbUseODBC)
    wk.DefaultCursorDriver = dbUseODBC
    
    Set db = wk.OpenDatabase("", False, False, connStr)
    isopen = True
    
    End Sub
    Current ADO setup:
    Sub openconnection3()
    'If Isopen = True Then
    '    Exit Sub
    'End If
    
    'Open Connection to System
    Set cnn = New ADODB.Connection
    cnn.Properties("Prompt") = adPromptComplete
    sConnString = "Driver={Client Access ODBC Driver (32-bit)};System=database;"
    cnn.Open sConnString
    
    Set cmd = New ADODB.Command
    cmd.ActiveConnection = cnn
    'Isopen = True
    Set rs = New ADODB.Recordset
    End Sub
    I could like to get the if statement working if I can

    Function call for DAO:
    Function GetDCQOH(Line, Item) As Double
    
    Dim rstRecordset As DAO.Recordset
    
    On Error GoTo errors
    
    'On Error GoTo trap
    
    openconnection
    
    sqlstatement = _
        "SELECT iqtyoh from database where ILINE = '" & Line & "' and IITEM# = '" & Item & "'"
    
    Set rstRecordset = db.OpenRecordset(sqlstatement, DAO.dbOpenSnapshot)
    
    'get the data
    GetDCQOH = rstRecordset.Fields(0).Value
    
    'close the connections and clean up
    rstRecordset.Close
    Set rstRecordset = Nothing
    
    GoTo noerrors
    
    errors:
    'MsgBox Error
    
    noerrors:
    
    
    End Function
    ADO Function call:
    Function GetQOO(Line, Item) As Double
    
    Dim sSQL As String
    
    On Error GoTo errors
    
    'On Error GoTo trap
    
    openconnection3
    
    sSQL = _
        "SELECT iqtyoo from database where ILINE = '" & Line & "' and IITEM# = '" & Item & "'"
    
    rs.Open sSQL, cnn, adOpenKeyset, adLockOptimistic
    
    'get the data
    GetQOO = rs.Fields(0).Value
    
    'close the connections and clean up
    rs.Close
    Set rs = Nothing
    
    GoTo noerrors
    
    errors:
    'MsgBox Error
    
    noerrors:
    
    
    End Function

    Any help will be greatly appreciated!
    Last edited by popfan; 01-10-2012 at 11:08 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1