Hi Folks -
I am designing a rather simple solution although I an experiencing some pretty servere performance issues due to the size of my dataset. Allow me to explain.
I have an Access Table that I am populating via an INSERT, which SELECTs from a linked excel file that is refreshed each month. The excel file is ~70 rows has a column for Cost Center which from Workday, comes in an abbreviated form. Therefore, I have another linked table which is a "Master" Cost Center file that is refreshed daily from our MDM system.
The objective is to take the partial Cost Center ID from my linked excel file and "search" the "Master" file for the same digits. If found, return the fully quality ID otherwise return NULL.
My problem (I think) is the size of each data set. My excel file is 70k rows and the "Master" Cost Center linked file/table is 300k rows. I'm calling my VBA function from my SELECT statement. My function is as follows:
Code:
Function LongNamenew(CostCentr_id As String) As String
Dim abbrev As Variant
Dim gUnderScore As Variant
Dim gHyphen As Variant
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
'Get the database and Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("LT-SAP_to_Cost_Center_Full_Reference_Mapping")
' CostCentr_id is sent as XXX - XXXX_xxxxxxx so extract the digits following the "_" symbol
abbrev = Left(CostCentr_id, 3)
gUnderScore = Mid(CostCentr_id, InStrRev(CostCentr_id, "_") + 1, 256)
gHyphen = Mid(CostCentr_id, InStrRev(CostCentr_id, "-") + 1, 256)
If abbrev = "SAU" Then
'Search for the first matching record
rst.FindFirst "[Element] LIKE '*" & gHyphen & "*'"
Else
'Search for the first matching record
rst.FindFirst "[Element] LIKE '*" & gUnderScore & "*'"
End If
'Check the result
If Not rst.NoMatch Then
LongNamenew = rst!Element
Else
LongNamenew = ""
End If
End Function
The challenge I am running into is that each time I hit the function, I'm opening the Recordset. Is there a more efficient way to meet my needs? Perhaps store the Recordset into a variable and just search the variable? I'm not sure. Right now it runs for hours and never ends up finishing.
Thank you, all!