Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default ADO connection retrieving data to Excel using EXCEL-VBA

How can I tell the "recordset" during the process of pasting the data to the
spreadsheet, not to paste blank values, I mean, only import values < "" ONLY?
Thanks

Coco
This is my working fine ADO connection but it is retrieving ALL records for
that table, including Blank values.


DBConnection = "Provider=MSDASQL.1 ........."
SqlString = "SELECT UNITX,DESCRIPTION from UNIT"
Dim TargetRange As Range
Set TargetRange = Worksheets("Sheet1").Range("A1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set rs = New ADODB.Recordset
With rs
.Open SqlString, DBConnection
TargetRange.Offset(0, 0).CopyFromRecordset rs ' recordset data
End With
rs.Close
Set rs = Nothing
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default ADO connection retrieving data to Excel using EXCEL-VBA

I am not sure if your data source uses blanks ("") or Null values, but here
is the way to account for both:
SqlString = "SELECT UNITX, DESCRIPTION from UNIT WHERE DESCRIPTION<'' AND
DESCRIPTION IS NOT NULL AND UNIT <'' AND UNIT IS NOT NULL"

"coco" wrote:

How can I tell the "recordset" during the process of pasting the data to the
spreadsheet, not to paste blank values, I mean, only import values < "" ONLY?
Thanks

Coco
This is my working fine ADO connection but it is retrieving ALL records for
that table, including Blank values.


DBConnection = "Provider=MSDASQL.1 ........."
SqlString = "SELECT UNITX,DESCRIPTION from UNIT"
Dim TargetRange As Range
Set TargetRange = Worksheets("Sheet1").Range("A1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set rs = New ADODB.Recordset
With rs
.Open SqlString, DBConnection
TargetRange.Offset(0, 0).CopyFromRecordset rs ' recordset data
End With
rs.Close
Set rs = Nothing

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default ADO connection retrieving data to Excel using EXCEL-VBA

In the database both values are blank and when I open the table this case
only happens for record 1.

I tried with NULL but it did not work, any other idea?

Thanks

Coco


"K Dales" wrote:

I am not sure if your data source uses blanks ("") or Null values, but here
is the way to account for both:
SqlString = "SELECT UNITX, DESCRIPTION from UNIT WHERE DESCRIPTION<'' AND
DESCRIPTION IS NOT NULL AND UNIT <'' AND UNIT IS NOT NULL"

"coco" wrote:

How can I tell the "recordset" during the process of pasting the data to the
spreadsheet, not to paste blank values, I mean, only import values < "" ONLY?
Thanks

Coco
This is my working fine ADO connection but it is retrieving ALL records for
that table, including Blank values.


DBConnection = "Provider=MSDASQL.1 ........."
SqlString = "SELECT UNITX,DESCRIPTION from UNIT"
Dim TargetRange As Range
Set TargetRange = Worksheets("Sheet1").Range("A1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set rs = New ADODB.Recordset
With rs
.Open SqlString, DBConnection
TargetRange.Offset(0, 0).CopyFromRecordset rs ' recordset data
End With
rs.Close
Set rs = Nothing

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default ADO connection retrieving data to Excel using EXCEL-VBA

I tried with "" and it works fine
Thank you

Coco

"K Dales" wrote:

I am not sure if your data source uses blanks ("") or Null values, but here
is the way to account for both:
SqlString = "SELECT UNITX, DESCRIPTION from UNIT WHERE DESCRIPTION<'' AND
DESCRIPTION IS NOT NULL AND UNIT <'' AND UNIT IS NOT NULL"

"coco" wrote:

How can I tell the "recordset" during the process of pasting the data to the
spreadsheet, not to paste blank values, I mean, only import values < "" ONLY?
Thanks

Coco
This is my working fine ADO connection but it is retrieving ALL records for
that table, including Blank values.


DBConnection = "Provider=MSDASQL.1 ........."
SqlString = "SELECT UNITX,DESCRIPTION from UNIT"
Dim TargetRange As Range
Set TargetRange = Worksheets("Sheet1").Range("A1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set rs = New ADODB.Recordset
With rs
.Open SqlString, DBConnection
TargetRange.Offset(0, 0).CopyFromRecordset rs ' recordset data
End With
rs.Close
Set rs = Nothing

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieving data from old Excel formats Paul Cannard Excel Discussion (Misc queries) 2 January 7th 08 12:23 PM
Retrieving Data in excel Siddarth Jain Excel Worksheet Functions 1 November 13th 07 10:24 AM
internet connection via excel macro at timed intervels & save data to excel file. Sam Excel Worksheet Functions 1 July 22nd 07 06:08 AM
Retrieving SQL data into Excel - Part II Rob Setting up and Configuration of Excel 0 June 29th 06 10:47 PM
Retrieving SQL data into Excel Rob Setting up and Configuration of Excel 1 June 27th 06 11:18 PM


All times are GMT +1. The time now is 12:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"