首先你得去
Tools -> Options -> General -> Error trapping
并选择
Break on Unhandled errors
添加到代码:
Public Sub Teste()
On Error GoTo Err
If TextBox_username.Value = "" Or TextBox_password.Value = "" Then
MsgBox "Enter Username and Password"
Else
oConn.Open "Driver={Amazon Redshift (x86)};" & _
"Server=" & strServerAddress & ";" & _
"Port=123;" & _
"Database=abc;" & _
"Uid=" & strUsername & ";" & _
"Pwd=" & strPassword & ";"
oConn.commandTimeout = 600
If oConn.State = 1 Then
End If
End If
Exit Sub
Err:
Msgbox Err.Description 'Your custom message
End Sub