title: ADODB error handling variable not setting
body: <p>I building an ADODB error trap but for some reason, by errSQL.Number and errSQL.Description both give me a "Object variable or With Block variable not set." error....here is my code so far...I have the active x object enabled and I thought that .number and .description are correct...any help would be awesome! The query I'm running also purposely will send an error. </p>
  
  <p>When I comment the error trap out, I do get a message box with a SQL syntax error but can't seem to trap it like below...</p>
  
  <pre><code>Public errSQL              As ADODB.Error
  Public strErrODBC          As String
  
  Private Sub verifySQL()
  
  Dim strSQL2             As String
  Dim cn          As New ADODB.Connection
  Dim cdTxt               As String
  Dim rs                  As New ADODB.Recordset
  Dim intVerify           As Integer
  
  
  On Error GoTo ODBCErrorHandler
  
  
  
  cn.ConnectionString = "DSN=source;"
  
  cn.Open
  
  If cn.State = adStateOpen Then
  
      rs.Open "SELECT CASE WHEN MAX((CASE WHEN " &amp; Forms!dlgSplitName.lstbxFlds.Column(0) &amp; " " &amp; cdTxt &amp; " THEN 1 ELSE 0 END)) =1 THEN 1 ELSE 0 END FROM table;", cn
  Else
  
  End If
  
  intVerify = rs.Fields(0).Value
  
  If intVerify = 1 Then
  
          insrt_Test
  
  
      ElseIf intVerify = 0 Then
  
          MsgBox "No records were found with the code text logic.", vbExclamation + vbOKOnly, "Spliy by Notification"
  
      End If
  
  
  ODBCErrorHandler:
  
  
  
  
      Debug.Print errSQL.Number
      Debug.Print errSQL.Description
  
    strErrODBC = "A SQL error was encountered with the code text logic." &amp; vbCrLf
    strErrODBC = strErrODBC &amp; "Error " &amp; errSQL.Number &amp; vbCrLf
    strErrODBC = strErrODBC &amp; " " &amp; errSQL.Description
  
  
    MsgBox strErrODBC &amp; vbCrLf &amp; "Please try again.", vbCritical, "Split by field code text error."
  
  cn.Close
  
  
  End Sub
  </code></pre>