title: Data fetching from SQL Server in VBA
body: <p>Hi Below is my code, i am not able to fetch the data from my SQL server,
   its throwing error as </p>
  
  <pre><code>Compiler error :  object required.
  </code></pre>
  
  <p>There is no problem with the connection, connection is sucessful.</p>
  
  <p>please correct my code, help me with this thing</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Set SQLConn = CreateObject("ADODB.Connection")
  
  SQLConn.Open "provider =sqloledb; Data Source = xxxx; Initial Catalog = jjjj; User Id = yyyy; Password = zzzz"
  
         MsgBox "Connection Succesful"
  
  Set SQLData = CreateObject("ADODB.Recordset")
  With SQLData
  
      ' Assign the Connection object.
      .ActiveConnection = SQLConn
  
      ' Extract the required records.
      .Open "select invoice_num, invoice_date, invoice_amount from im_invoice where billing_account = 'HS0076A' and invoice_date ='01-apr-2011'"
  
      ' Copy the records into cell A1 on Sheet1.
      Sheet1.Range("A1").CopyFromRecordset SQLData
  
      ' Tidy up
       .Close
  
  End With
  
  SQLConn.Close
  Set SQLData = Nothing
  Set SQLConn = Nothing
  
  End Sub
  </code></pre>
  
  <p>Thank you</p>
  
  <p>thank you its working .... :)</p>