Hey,
I created a UDF in VBA that calls a value from an Access Database. It works, but it is absurdly SLOW. It takes like 20 secs to get 1 cell of data, and if you try to call >5 cells it will lock up excel. Does anyone have any ideas on how to make this faster and thus actually usable? Code below:
Function GetNumber(ID As String, Month As Date)
Dim db As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT Number FROM Table1 " & _
"WHERE [PersonID] = ('" & ID & "') AND Date = (#" & Month & "#);"
Set db = New ADODB.Connection
file = "C:\Database.accdb"
With db
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open file
End With
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open Source:=strSQL, ActiveConnection:=db, CursorType:=adOpenForwardOnly, _
LockType:=adLockReadOnly
GetNumber = rst.Fields("Number").Value
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
End Function
Thanks!
Moderator Edit:
Welcome to the forum, sike64.
Please notice that [CODE] tags have been added to your post. The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
Thanks.
Bookmarks