ijourneaux
New Member
- Joined
- Jul 9, 2018
- Messages
- 36
I have queried a SQL database to get a recodset
My orignal attempt to write the data to a worksheet was
When the command .CopyFromRecordset is executed, the cell formatting a some cells in another worksheet is unexpectedly changed from Number to Date.
Works without corrupting the other worksheet. Anyone have any thoughts on what might be happening when using .CopyFromRecordset?
VBA Code:
cnn.Open ConnectionString
cnn.CommandTimeout = 900
rst.Open StrQuery, cnn
VBA Code:
ThisWorkbook.Worksheets("RMS Data").Range("A2").CopyFromRecordset rst
fldCount = rst.Fields.Count
rst.MoveFirst
recArray = rst.GetRows
When the command .CopyFromRecordset is executed, the cell formatting a some cells in another worksheet is unexpectedly changed from Number to Date.
VBA Code:
fldCount = rst.Fields.Count
Set rngDst = ThisWorkbook.Worksheets("RMS Data").Range("A2")
With rst
If Not .BOF And Not .EOF Then
.MoveFirst
While Not .EOF
For i = 0 To .Fields.Count - 1
rngDst.Offset(, i) = .Fields(i).value
Next i
rst.MoveNext
Set rngDst = rngDst.Offset(1)
Wend
End If
End With
Works without corrupting the other worksheet. Anyone have any thoughts on what might be happening when using .CopyFromRecordset?