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!
Bookmarks