Sub Form_Unload (Cancel As Integer) Dim T& If MSComm1.PortOpen Then '--- Wait 10 seconds for data to be transmitted T& = Timer + 10 Do While MSComm1.OutBufferCount Ret = DoEvents() If Timer > T& Then Select Case MsgBox("Data cannot be sent", 34) '--- Abort Case 3 Cancel = True Exit Sub '--- Retry Case 4 T& = Timer + 10 '--- Ignore Case 5 Exit Do End Select End If Loop MSComm1.PortOpen = 0 End If '--- If log file is open, flush and close it If hLogFile Then MCloseLog_Click End End Sub