Timing Delays in VBA

后端 未结 12 2251
陌清茗
陌清茗 2020-11-28 13:48

I would like a 1 second delay in my code. Below is the code I am trying to make this delay. I think it polls the date and time off the operating system and waits until the

12条回答
  •  青春惊慌失措
    2020-11-28 14:12

    For MS Access: Launch a hidden form with Me.TimerInterval set and a Form_Timer event handler. Put your to-be-delayed code in the Form_Timer routine - exiting the routine after each execution.

    E.g.:

    Private Sub Form_Load()
        Me.TimerInterval = 30000 ' 30 sec
    End Sub
    
    Private Sub Form_Timer()
    
        Dim lngTimerInterval  As Long: lngTimerInterval = Me.TimerInterval
    
        Me.TimerInterval = 0
    
        '
    
        Me.TimerInterval = lngTimerInterval
    End Sub
    

    "Your Code goes here" will be executed 30 seconds after the form is opened and 30 seconds after each subsequent execution.

    Close the hidden form when done.

提交回复
热议问题