簡體   English   中英

在 MS Access (VBA) 中模擬多線程

[英]Simulate Multi-Threading in MS Access (VBA)

我編寫了一個在 Access 數據庫中運行的 VBA 腳本。 該腳本在各種表上查找值,並根據值的組合將屬性分配給主表。

該腳本按預期工作,但是,我正在處理數百萬條記錄,因此需要很長時間。

我想將過程分解成更小的部分,並在不同的線程上同時運行腳本。

在我開始嘗試構建解決方案之前,我想知道:

  1. 根據您的經驗,這會提高性能嗎? 或者這個過程需要同樣長的時間?
  2. 我正在考慮使用 Powershell 或 VBScript 來完成此任務。 有什么需要注意的障礙嗎?

請注意:由於客戶端將運行,我必須使用 Access 作為后端,如果我使用 Powershell,它必須是版本 1.0。

我知道這些是非常模糊的問題,但感謝任何基於先前經驗的反饋。 謝謝

只是想用我的最終解決方案發回...

我嘗試了以下方法,根據 60,000 條記錄樣本大小的其他表中的值組合將屬性分配給主表:

Solution 1: Used a combination of SQL queries and FSO Dictionary objects to assign attribute
Result: 60+ minutes to update 60,000 records

Solution 2: Ran script from Solution 1 concurrently from 3 separate instances of Excel
Result: CPU was maxed out (Instance 1 - 50% of CPU, Instances 2 and 3 - 25% each); stopped the code after an hour since it wasn't a viable solution

Solution 3: Tried using SQL UPDATE queries to update main table with the attribute
Result: This failed because apparently Access does not allow for a join on an UPDATE sub-query (or I just stink at writing SQL)

Solution 4 (Best Result): Selected all records from main table that matched the criteria for each attribute, 
 output the records into csv and assigned the attribute to all records in the csv file. 
 This created a separate file for each attribute, all in the same format. I then 
 imported and appended all of the records from the csv files into a new main table.  
Result: 2.5 minutes to update 60,000 records

特別感謝 Pynner 和 Remou,他們建議將數據寫入 csv。

我從沒想過這會是用屬性更新記錄的最快方法。 我可能會放棄這個項目,認為如果你沒有提出這個建議,Access 和 VBA 是不可能完成的。 非常感謝您分享您的智慧!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM