Excel VBA - Reading SQL data | Now you see it, Now you don't

Deleted
Not applicable

Hello, I'm having the damnedest time trying to figure out what Excel is doing with my data.  I have an Excel spreadsheet where I connect to a SQL table using ADO to read data and enter that data into rows and columns.  That all works, well mostly, but I have a situation where data in certain fields of a recordset doesn't get written into Excel.  As I'm debugging my code, I've run into a situation where I can see the missing data - and then it disappears.  Hopefully this image will make it clear.  

 

In the image I have a break point on a line and my cursor positioned on the field value such that when I "F5" Continue the field value is instantly displayed.  Both the left and right image is the same break point - the only change between the two is me moving my cursor off and then back on the field value.  Now you see it, now you don't.

VanishingValue.jpg

I'm using Excel 2010 (that's what we have here) and connecting to SQL using ADO connection.  I can stop debugging and restart the module and the issues happens again and again to the same 40 or so records (fields).

 

 

The recordset returned is 17 rows with 128 columns each.  Not big data so I don't think it's RAM related.

 

Any ideas or suggestions would be appreciated!

Thanks

Jim

 

2 Replies

I have the same issue. I converted from an Access database (where the same code worked) to an SQL database. The data exists as I am able to query the database using Excel and get the data. The VBA program actually creates this data and posts it to SQL. But the subsequent read back into the recordset has the same symptoms you indicated.

@e have determined the problem. The field(s) in question are defined as NCHAR (variable length). Changing to a static length eliminates the issue. But this seems like a VBA issue.