title: Query database through Excel VBA
body: <p>I am a beginner in Excel VBA. I want to query data from Teradata database and give the output into the rows of an excel sheet. When i write the below code: </p>
  
  <pre><code>Private Sub CommandButton1_Click()
      Dim conn As Connection
      Dim rec1 As Recordset
      Dim thisSql As String
      Set conn = New Connection
      conn.Open "Driver=Teradata; DBCName=" &amp; DBCName &amp; ";UID=" &amp; UID &amp; ";PWD=" &amp; PWD
      thisSql = "simple select qyery here"
      With .QueryTables.Add(Connection:=conn, Destination:=.Range("A1"))
          .Sql = thisSql
          .Name = "data"
          .FieldNames = True
          .Refresh BackgroundQuery:=False
      End With
  End Sub
  </code></pre>
  
  <p>I am getting the error saying <strong>'Compiler error: User-defined type not defined'</strong></p>
  
  <p>how to overcome this error? Do i need to include anything in the code?</p>
  
  <p>Please help</p>
  
  <p>I am using MSVisualBasic 6.5 editor</p>