Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Strange behavior with Recordset

$
0
0

I've never seen anything like this before. The code is very straight forward. From within VBA I create an ADODB Connection, pass a query and return the result in a Recordset. Then I use CopyFromRecordset to dump the results into a column. However this time after I ran the code and looked at the results in the worksheet, most of the cells were blank, even though I expected every cell to have a value. I decided to step through the code and use the Immediate window to look at the values in the Recordset. So I stopped the code after this line:

'rs is the Recordset. cn is the Connection. strSQL is the SQL string

rs.Open strSQL, cn

stop

Then in the immediate I got this result:

?rs(0)

4 - Attorney

That is the expected result. but then it gets strange. I went back and hit enter on the rs(0) line and got this:

?rs(0)

NULL

4 - Attorney

Where it originally said 4- Attorney, now it says NULL. I didn't change anything. I didn't move to the next record. I simply asked for the first record again and it has now changed to NULL. 

What's going on?

tod


Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>