J
John Ortt
Hi Everyone,
I have inherrited a database which makes use of VB code to perform a stage
of the weekly update.
The update works effectively but I have now been tasked with reducing the
amount of time it takes and the code section is by far the longest process.
I have tried to add comments to the code within my understanding but if
anybody can spot errors in my comments, or can think of a better/more
efficient way of performing the same task I would be very grateful.
Thanks in advance,
John
CODE FOLLOWS
/////////////////////////////
Function Update_Details_With_COOP_Data()
' This query updates the Details Table with the latest info from the Coop
Purchase Orders Table where there is a firm order date
Dim MyDB As Database, Import_Query As Recordset, MyWrk As Workspace
Dim strSQL As String, Coop_SQL As String, COOP_Data As Recordset
Set MyWrk = DBEngine.Workspaces(0)
Set MyDB = CurrentDb
strSQL = "SELECT * FROM Details_Table" ' Defines the variable strSQL
Set Import_Query = MyDB.OpenRecordset(strSQL) ' Selects all the records
from the Details Table and stores the data as Import_Query
With Import_Query ' Using the data for Import Query
..MoveFirst ' Move to the first line of data
Do Until .EOF ' Repeat the following code until it reaches the end of the
form (EOF)
Coop_SQL = "SELECT * FROM COOP_Purchase_Orders_Table WHERE
[COL_Link] =""" & Import_Query![Col_link] & """ ORDER BY [Firm_Date]"
' Select the lines in the "COOP_Purchase_Orders_Table" where the
"COL_Link" matches with the "Import_Query"
Set COOP_Data = MyDB.OpenRecordset(Coop_SQL)
If COOP_Data.RecordCount > 0 Then ' If there is a match then do the
following, otherwise go straight to the "End If"
.Edit
![AQUISITION] = COOP_Data![AQUISITION]
If COOP_Data![Firm_Date] <> "" Then ![Firm_Date] =
COOP_Data![Firm_Date]
![PO_Number] = COOP_Data![PO_Number]
![System] = COOP_Data![System]
![MMS_Link] = COOP_Data![MMS_Link]
.Update
End If
.MoveNext
Loop
End With
DoEvents
End Function
I have inherrited a database which makes use of VB code to perform a stage
of the weekly update.
The update works effectively but I have now been tasked with reducing the
amount of time it takes and the code section is by far the longest process.
I have tried to add comments to the code within my understanding but if
anybody can spot errors in my comments, or can think of a better/more
efficient way of performing the same task I would be very grateful.
Thanks in advance,
John
CODE FOLLOWS
/////////////////////////////
Function Update_Details_With_COOP_Data()
' This query updates the Details Table with the latest info from the Coop
Purchase Orders Table where there is a firm order date
Dim MyDB As Database, Import_Query As Recordset, MyWrk As Workspace
Dim strSQL As String, Coop_SQL As String, COOP_Data As Recordset
Set MyWrk = DBEngine.Workspaces(0)
Set MyDB = CurrentDb
strSQL = "SELECT * FROM Details_Table" ' Defines the variable strSQL
Set Import_Query = MyDB.OpenRecordset(strSQL) ' Selects all the records
from the Details Table and stores the data as Import_Query
With Import_Query ' Using the data for Import Query
..MoveFirst ' Move to the first line of data
Do Until .EOF ' Repeat the following code until it reaches the end of the
form (EOF)
Coop_SQL = "SELECT * FROM COOP_Purchase_Orders_Table WHERE
[COL_Link] =""" & Import_Query![Col_link] & """ ORDER BY [Firm_Date]"
' Select the lines in the "COOP_Purchase_Orders_Table" where the
"COL_Link" matches with the "Import_Query"
Set COOP_Data = MyDB.OpenRecordset(Coop_SQL)
If COOP_Data.RecordCount > 0 Then ' If there is a match then do the
following, otherwise go straight to the "End If"
.Edit
![AQUISITION] = COOP_Data![AQUISITION]
If COOP_Data![Firm_Date] <> "" Then ![Firm_Date] =
COOP_Data![Firm_Date]
![PO_Number] = COOP_Data![PO_Number]
![System] = COOP_Data![System]
![MMS_Link] = COOP_Data![MMS_Link]
.Update
End If
.MoveNext
Loop
End With
DoEvents
End Function