私はいくつかの VBA マクロに取り組んでいます。また、ADODB.Recordset を使用して Access データベースのデータにアクセスしています。
ここで、テーブル内のレコードをループする必要があり、このループでは、別の関数で同じテーブルを更新する必要もあります。
これがコードです(読みやすいようにクリーンアップされています)。
Dim strSql As String
Dim rstCycles As adodb.Recordset
strSql = "SELECT * FROM tblCycles WHERE DatePlanning = #" & dteCurrentDate & "#"
Set rstCycles = SelectQuery(strSql)
While Not rstCycles.EOF
if ... then
rstCycles("NoCycle1") = ...
rstCycles.Update
end if
RefreshPlanning (*)
rstCycles.MoveNext
Wend
(*) この関数では、tblCycles テーブルで選択を実行します。
問題は rstCycles.Update の後であり、データはすぐにディスクに記録されないため、RefreshPlanning の呼び出しは更新されたデータを読み取りません。更新後に「1 秒の一時停止」を設定すると、すべて問題ありません。ループで一種の一時停止を使用したくありません。別の解決策はありますか?
アップデート - - - - - - - -
RefreshPlanning は、tblCycles テーブルに基づいて Excel シートを更新する単純な関数です。
Sub RefreshPlanning(DatePlanning As Date, CodeEquipement As String)
Dim strSql As String
Dim rstCycles As adodb.Recordset
strSql = "SELECT * FROM tblCycles WHERE DatePlanning = #" & DatePlanning & "# AND CodeEquipement = '" & CodeEquipement & "'"
Set rstCycles = SelectQuery(strSql)
While Not rstCycles.EOF
' Some code here to update my excel sheet
' ...
rstCycles.MoveNext
Wend
End Sub