I'm suprised no one posted an example already. Anyhow, try this. Put the follwoing in a Module
Put the following into a Form with a CommandButtonCode:Declare Function SetTimer Lib "user32" (ByVal HWND As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" (ByVal HWND As Long, ByVal nIDEvent As Long) As Long Function TimerProc(HWND As Long, uMsg As Long, EventID As Long, dwTime As Long) As Long 'This MessageBox will display every second msg = MsgBox("This will display every second until you press no", vbYesNo) 'If "No" is pressed then destroy the Timer If msg = vbNo Then Call KillTimer(Form1.HWND, 1000) End If End Function
Code:Private Sub Command1_Click() 'The Timer will begin when this button is clicked Call SetTimer(Me.HWND, 1000, 1000, AddressOf TimerProc) End Sub




Reply With Quote