进度条未出现在我的表单中

时间:2012-09-18 08:38:23

标签: vba ms-access ms-access-2003

我想向用户显示进度条,同时我删除并插入表格。我使用这段代码但我看不到表单中的进度条。你能帮我解决这个问题吗?

SysCmd acSysCmdInitMeter, "Updating: ", 1000
For Counter = 1 To 1000
    SysCmd acSysCmdUpdateMeter, Counter

    On Error GoTo PROC_ERR
  Set db = CurrentDb
   ssql = "DELETE FROM Test_Table"
   db.Execute ssql, dbFailOnError

  ssql = "INSERT INTO Test_Table SELECT DISTINCT tb_KonzeptDaten.DFCC,  " _
  & "tb_KonzeptDaten.OBD_Code AS Konzept_Obd,tb_KonzeptDaten.DFC " _
  & "FROM tb_KonzeptDaten"
  db.Execute ssql, dbFailOnError
  Msgbox "Die Tabelle wurde erfolgreich aktualisiert"
ExitSub:
'Clean  Up Code
Exit Sub
PROC_ERR:
Msgbox Err.Description
GoTo ExitSub:

Next Counter
SysCmd acSysCmdRemoveMeter

谢谢

修改 我想,我应该让我的问题更简单。 我想在状态栏中显示进度条,因此我已经将这段代码用于测试:

Private Sub Befehl80_Click()
 Dim Progress_Amount As Integer, RetVal As Variant
  RetVal = SysCmd(acSysCmdInitMeter, "Reading Data...", 2000)
  For Progress_Amount = 1 To 2000
  RetVal = SysCmd(acSysCmdUpdateMeter, Progress_Amount)
  Next Progress_Amount 
End Sub

我有这个期望,如果我单击此按钮我能够看到状态栏,但不幸的是,当我单击此按钮时我看不到它,但如果我关闭此访问项目,则会出现此状态栏。你有什么想法来解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

这是一个屏幕刷新问题。在代码完成运行之前,您的屏幕不会刷新。为了解决这个问题,您需要使用DoEvents命令来允许屏幕刷新,而仍在运行代码。

SysCmd acSysCmdInitMeter, "Updating: ", 1000
For Counter = 1 To 1000
    SysCmd acSysCmdUpdateMeter, Counter

    ' Put your DoEvents here, so the screen has time to refresh
    DoEvents

    On Error GoTo PROC_ERR
  Set db = CurrentDb
   ssql = "DELETE FROM Test_Table"
   db.Execute ssql, dbFailOnError

  ssql = "INSERT INTO Test_Table SELECT DISTINCT tb_KonzeptDaten.DFCC,  " _
  & "tb_KonzeptDaten.OBD_Code AS Konzept_Obd,tb_KonzeptDaten.DFC " _
  & "FROM tb_KonzeptDaten"
  db.Execute ssql, dbFailOnError
  Msgbox "Die Tabelle wurde erfolgreich aktualisiert"
ExitSub:
'Clean  Up Code
Exit Sub
PROC_ERR:
Msgbox Err.Description
GoTo ExitSub:

Next Counter
SysCmd acSysCmdRemoveMeter