0

I want to show a Progress bar to user, while I delete and Insert into a table. I use this block of code but I can't see the progressbar in the form. Would you please help me to solve this problem?

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

thank you

EDIT: I think, that I should make my question simpler. I want to show progressbar in statusbar hence I've wirte this block of code for test:

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

I have this expectation, if the I click this button I'm able to see the statusbar, but unfortunatly I can't see it when I click this button, but if I close this access project then this statusbar appear. Have you any idee to solve this problem?

Kabi
  • 1,905
  • 5
  • 20
  • 22

1 Answers1

1

This is a screen refresh issue. Your screen isn't being refreshed until the code has completed running. In order to fix this, you will need to use a DoEvents command to allow the screen to refresh while it's still running the code.

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
Johnny Bones
  • 8,786
  • 7
  • 52
  • 117