Put a call to DoEvents in the Loop, (this will allow other events to fire), then in have the loop exit if the time expires or a Boolean Flag is set, then set the Boolean Flag in the Forms QueryUnload Event, i.e.
Code:
Private bStopped As Boolean
Private Sub Form_Activate()
Dim tTimer As Single
tTimer = Timer
'Loop for 30 Seconds, or until the form is unloaded
While Not bStopped And (Timer - tTimer) < 30
Caption = Val(Caption) + 1
DoEvents
Wend
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'Set the Boolean Flag to indicate to the Loop that it should Stop
bStopped = True
End Sub