Running a Access query that calls a VBA function and it takes over seven hours to run. Without the Function call the query runs in 4 mins. There are four (4) tables joined together. The main table has 90k rows and the other three are outter joins. Four (4) mins is reasonable to run the query under Office on a workstation. But seven hours is not when the VBA function is called. The Function uses DAO. A Select is opened and if the row is found a column value is returned. If the row is not found the first available row is updated. Stepping thru the VBA module does not appear to show anything wrong, but letting it run takes too long. Why would the VBA module run so slowly? Running Office 2007 SP2 w/XP SP3.
Query:
SELECT DISTINCT fGetProfileName([Otrans for eLabel Temp 2].[eLabel FormNum],[Otrans for eLabel Temp 2].[eLabel Job Function],[Otrans for eLabel Temp 2].[Otran],(Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),[Otran CSI by Otran].[csi_id]))))) AS [Profile Name], "Form " & [Otrans for elabel Temp 2].[elabel FormNum] & "-" & [Otrans for elabel Temp 2].[elabel Job Function] & " CSI " & Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),[Otran CSI by Otran].[csi_id]))) AS [Profile Desc], [Otrans for elabel Temp 1].[Mdl Type], [Otrans for elabel Temp 1].[Mdl Resource], [Otrans for elabel Temp 1].[Mdl Dept/Div/Zone Desc], [Otrans for elabel Temp 2].[eLabel FormNum] AS Form, [Otrans for elabel Temp 2].[eLabel Job Function] AS [Job Function], Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),IIf(IsNumeric([Otran CSI by Otran].[csi_id]),[Otran CSI by Otran].[csi_id],'43458')))) AS [CSI Number], [Otrans for elabel Temp 2].Otran, [Otrans for elabel Temp 2].[Otran Resource] & [Otrans for elabel Temp 2].[Otran Owner] & ' ' & [Otrans for elabel Temp 2].[Otran] AS [Otran String], [Otran CSI by Otran].Description AS [Otran Description], (select Top 1 [eLabel Approvers].[First name] & ' ' & [eLabel Approvers].[Surname] & ' - ' & [eLabel Approvers].[SOEID] from [eLabel Approvers] where [eLabel Approvers].[Form] = [Otrans for eLabel Temp 2].[eLabel FormNum]) AS [Approver First/Last/SOEID], [Otran CSI by Otran].Usage AS [Lpar Usage], [Otran to CSI Mapping].[CSI NUMBER] AS [Otran CSI Number], [Otran CSI by Otran].CSI_ID AS [Lpar CSI], [Otrans for elabel Temp 2].[Otran Resource], [Otrans for elabel Temp 2].[Otran Owner], [Otran to CSI Mapping].Obsolete AS [Otran CSI Obsolete], [Otran CSI by Otran].[Dept Manager] AS [Dept Manager], [Otran CSI by Otran].[Appl Manager last name] AS [Appl Manager Last Name]
FROM (([Otrans for elabel Temp 2] LEFT JOIN [Otran to CSI Mapping] ON [Otrans for elabel Temp 2].Otran = [Otran to CSI Mapping].Entitlement) LEFT JOIN [Otrans for elabel Temp 1] ON ([Otrans for elabel Temp 2].[Profile Name] = [Otrans for elabel Temp 1].[Profile Name]) AND ([Otrans for elabel Temp 2].[eLabel FormNum] = [Otrans for elabel Temp 1].[eLabel FormNum]) AND ([Otrans for elabel Temp 2].[eLabel Job Function] = [Otrans for elabel Temp 1].[eLabel Job Function])) LEFT JOIN [Otran CSI by Otran] ON [Otrans for elabel Temp 2].Otran = [Otran CSI by Otran].Transaction
WHERE ((([Otrans for elabel Temp 2].Otran)<>'&&') AND (([Otran to CSI Mapping].Obsolete)='No' Or ([Otran to CSI Mapping].Obsolete) Is Null))
ORDER BY [Otrans for elabel Temp 2].[eLabel FormNum], [Otrans for elabel Temp 2].[eLabel Job Function], Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),IIf(IsNumeric([Otran CSI by Otran].[csi_id]),[Otran CSI by Otran].[csi_id],'43458')))), [Otrans for elabel Temp 2].Otran;
Function:
Option Compare Database
Option Explicit
Public Function fGetProfileName(FormNum, JobFunction, Otran, CsiNum As String) As String
Dim dbsMfes_Reconfig_Automation As DAO.Database
Dim rstGetProfileName As DAO.Recordset
Dim rstAddProfileName As DAO.Recordset
Dim strGetProfileNameSql As String
Dim strAddProfileNameSql As String
Set dbsMfes_Reconfig_Automation = CurrentDb
strGetProfileNameSql = _
"SELECT [Profile Name], Form, [Job Function], [CSI Number] " & _
"FROM [Profile Names] " & _
"WHERE [Profile Names].[Form] = '" & FormNum & "' " & _
"AND [Profile Names].[Job function] = '" & JobFunction & "' " & _
"AND [Profile Names].[CSI Number] = '" & CsiNum & "'"
Set rstGetProfileName = _
dbsMfes_Reconfig_Automation.OpenRecordset(strGetProfileNameSql, dbOpenSnapshot)
If rstGetProfileName.EOF = False Then
fGetProfileName = rstGetProfileName![Profile Name]
Else
strAddProfileNameSql = _
"SELECT Top 1 [Profile Name], Form, [Job Function], [CSI Number] " & _
"FROM [Profile Names] " & _
"WHERE [Profile Names].[Form] Is Null"
Set rstAddProfileName = _
dbsMfes_Reconfig_Automation.OpenRecordset(strAddProfileNameSql)
If rstAddProfileName.EOF = True Then
fGetProfileName = ""
[TempVars]![ErrorCode] = 1
Else
rstAddProfileName.Edit
rstAddProfileName![Form] = FormNum
rstAddProfileName![Job Function] = JobFunction
rstAddProfileName![CSI Number] = CsiNum
rstAddProfileName.Update
fGetProfileName = rstAddProfileName![Profile Name]
End If
rstAddProfileName.Close
End If
rstGetProfileName.Close
dbsMfes_Reconfig_Automation.Close
Set rstGetProfileName = Nothing
Set rstAddProfileName = Nothing
End Function
Profile Table:
I:\Databases\Retail\Retail MFES TSS CFEERS.mdb Tuesday, July 16, 2013
Table: Profile Names Page: 1
Properties
Attributes: Linked Connect: ;DATABASE=S:\MFES\R
etail\Access
Databases\MFES
Reconfig Retail Profile
DateCreated: 7/9/2013 1:40:50 PM DefaultView: 2
DisplayViewsOnShare 1 Filter: ([Profile Names].[Job
function] Is Not Null AND
[Profile Names].[Job
function]<>"")
FilterOnLoad: False GUID: {guid {03BF4C73-D61B-
4976-A6C2-
HideNewField: False LastUpdated: 7/9/2013 1:40:50 PM
NameMap: Long binary data OrderBy: [Profile Names].[Job
OrderByOn: False OrderByOnLoad: True
Orientation: Left-to-Right RecordCount: -1
SourceTableName: Profile Names TotalsRow: False
Updatable: False
Columns
Name Type Size
ID Long Integer 4
Form Text 4
Job function Text 3
Profile Name Prefix Text 4
Profile Name Seq Text 4
Profile Name Text 8
CSI Number Text 10
Occurance Integer 2
Table Indexes
Name Number of
CSI Number 1
Fields:
CSI Number Ascending
Form 1
Fields:
Form Ascending
ID 1
Fields:
ID Ascending
PrimaryKey 1
Fields:
ID Ascending
Profile Name 1
Fields:
Profile Name Ascending
Query:
SELECT DISTINCT fGetProfileName([Otrans for eLabel Temp 2].[eLabel FormNum],[Otrans for eLabel Temp 2].[eLabel Job Function],[Otrans for eLabel Temp 2].[Otran],(Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),[Otran CSI by Otran].[csi_id]))))) AS [Profile Name], "Form " & [Otrans for elabel Temp 2].[elabel FormNum] & "-" & [Otrans for elabel Temp 2].[elabel Job Function] & " CSI " & Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),[Otran CSI by Otran].[csi_id]))) AS [Profile Desc], [Otrans for elabel Temp 1].[Mdl Type], [Otrans for elabel Temp 1].[Mdl Resource], [Otrans for elabel Temp 1].[Mdl Dept/Div/Zone Desc], [Otrans for elabel Temp 2].[eLabel FormNum] AS Form, [Otrans for elabel Temp 2].[eLabel Job Function] AS [Job Function], Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),IIf(IsNumeric([Otran CSI by Otran].[csi_id]),[Otran CSI by Otran].[csi_id],'43458')))) AS [CSI Number], [Otrans for elabel Temp 2].Otran, [Otrans for elabel Temp 2].[Otran Resource] & [Otrans for elabel Temp 2].[Otran Owner] & ' ' & [Otrans for elabel Temp 2].[Otran] AS [Otran String], [Otran CSI by Otran].Description AS [Otran Description], (select Top 1 [eLabel Approvers].[First name] & ' ' & [eLabel Approvers].[Surname] & ' - ' & [eLabel Approvers].[SOEID] from [eLabel Approvers] where [eLabel Approvers].[Form] = [Otrans for eLabel Temp 2].[eLabel FormNum]) AS [Approver First/Last/SOEID], [Otran CSI by Otran].Usage AS [Lpar Usage], [Otran to CSI Mapping].[CSI NUMBER] AS [Otran CSI Number], [Otran CSI by Otran].CSI_ID AS [Lpar CSI], [Otrans for elabel Temp 2].[Otran Resource], [Otrans for elabel Temp 2].[Otran Owner], [Otran to CSI Mapping].Obsolete AS [Otran CSI Obsolete], [Otran CSI by Otran].[Dept Manager] AS [Dept Manager], [Otran CSI by Otran].[Appl Manager last name] AS [Appl Manager Last Name]
FROM (([Otrans for elabel Temp 2] LEFT JOIN [Otran to CSI Mapping] ON [Otrans for elabel Temp 2].Otran = [Otran to CSI Mapping].Entitlement) LEFT JOIN [Otrans for elabel Temp 1] ON ([Otrans for elabel Temp 2].[Profile Name] = [Otrans for elabel Temp 1].[Profile Name]) AND ([Otrans for elabel Temp 2].[eLabel FormNum] = [Otrans for elabel Temp 1].[eLabel FormNum]) AND ([Otrans for elabel Temp 2].[eLabel Job Function] = [Otrans for elabel Temp 1].[eLabel Job Function])) LEFT JOIN [Otran CSI by Otran] ON [Otrans for elabel Temp 2].Otran = [Otran CSI by Otran].Transaction
WHERE ((([Otrans for elabel Temp 2].Otran)<>'&&') AND (([Otran to CSI Mapping].Obsolete)='No' Or ([Otran to CSI Mapping].Obsolete) Is Null))
ORDER BY [Otrans for elabel Temp 2].[eLabel FormNum], [Otrans for elabel Temp 2].[eLabel Job Function], Val(IIf(IsNull([Otran CSI by Otran].[csi_id]),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[csi Number]),IIf([Otran CSI by Otran].[csi_id] In ('000000','999999'),IIf(IsNull([otran to csi mapping].[CSI NUMBER]),'43458',[otran to csi mapping].[CSI NUMBER]),IIf(IsNumeric([Otran CSI by Otran].[csi_id]),[Otran CSI by Otran].[csi_id],'43458')))), [Otrans for elabel Temp 2].Otran;
Function:
Option Compare Database
Option Explicit
Public Function fGetProfileName(FormNum, JobFunction, Otran, CsiNum As String) As String
Dim dbsMfes_Reconfig_Automation As DAO.Database
Dim rstGetProfileName As DAO.Recordset
Dim rstAddProfileName As DAO.Recordset
Dim strGetProfileNameSql As String
Dim strAddProfileNameSql As String
Set dbsMfes_Reconfig_Automation = CurrentDb
strGetProfileNameSql = _
"SELECT [Profile Name], Form, [Job Function], [CSI Number] " & _
"FROM [Profile Names] " & _
"WHERE [Profile Names].[Form] = '" & FormNum & "' " & _
"AND [Profile Names].[Job function] = '" & JobFunction & "' " & _
"AND [Profile Names].[CSI Number] = '" & CsiNum & "'"
Set rstGetProfileName = _
dbsMfes_Reconfig_Automation.OpenRecordset(strGetProfileNameSql, dbOpenSnapshot)
If rstGetProfileName.EOF = False Then
fGetProfileName = rstGetProfileName![Profile Name]
Else
strAddProfileNameSql = _
"SELECT Top 1 [Profile Name], Form, [Job Function], [CSI Number] " & _
"FROM [Profile Names] " & _
"WHERE [Profile Names].[Form] Is Null"
Set rstAddProfileName = _
dbsMfes_Reconfig_Automation.OpenRecordset(strAddProfileNameSql)
If rstAddProfileName.EOF = True Then
fGetProfileName = ""
[TempVars]![ErrorCode] = 1
Else
rstAddProfileName.Edit
rstAddProfileName![Form] = FormNum
rstAddProfileName![Job Function] = JobFunction
rstAddProfileName![CSI Number] = CsiNum
rstAddProfileName.Update
fGetProfileName = rstAddProfileName![Profile Name]
End If
rstAddProfileName.Close
End If
rstGetProfileName.Close
dbsMfes_Reconfig_Automation.Close
Set rstGetProfileName = Nothing
Set rstAddProfileName = Nothing
End Function
Profile Table:
I:\Databases\Retail\Retail MFES TSS CFEERS.mdb Tuesday, July 16, 2013
Table: Profile Names Page: 1
Properties
Attributes: Linked Connect: ;DATABASE=S:\MFES\R
etail\Access
Databases\MFES
Reconfig Retail Profile
DateCreated: 7/9/2013 1:40:50 PM DefaultView: 2
DisplayViewsOnShare 1 Filter: ([Profile Names].[Job
function] Is Not Null AND
[Profile Names].[Job
function]<>"")
FilterOnLoad: False GUID: {guid {03BF4C73-D61B-
4976-A6C2-
HideNewField: False LastUpdated: 7/9/2013 1:40:50 PM
NameMap: Long binary data OrderBy: [Profile Names].[Job
OrderByOn: False OrderByOnLoad: True
Orientation: Left-to-Right RecordCount: -1
SourceTableName: Profile Names TotalsRow: False
Updatable: False
Columns
Name Type Size
ID Long Integer 4
Form Text 4
Job function Text 3
Profile Name Prefix Text 4
Profile Name Seq Text 4
Profile Name Text 8
CSI Number Text 10
Occurance Integer 2
Table Indexes
Name Number of
CSI Number 1
Fields:
CSI Number Ascending
Form 1
Fields:
Form Ascending
ID 1
Fields:
ID Ascending
PrimaryKey 1
Fields:
ID Ascending
Profile Name 1
Fields:
Profile Name Ascending
Last edited: