0

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

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

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

4

1 回答 1

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
于 2016-03-22T18:25:22.340 回答