On Apr 12, 9:42 pm, Mike <M...@discussions.microsoft.com> wrote:
> Could you post your code And has this CopyFromRecordset worked correct before
>
>
>
> "SSw...@gmail.com" wrote:
> > have been experiencing an issue that I just can not figure out.
> > Please let me know if there might be a more appropriate group to post
> > this question in. I am using Microsoft Jet OLEDB to retrieve a
> > recordset from an Access Database over our company network. I use a
> > "CopyFromRecordset" to write the data to a worksheet in Excel. I
> > will
> > often see the data that is imported corrupted. A good bit of the
> > data
> > appears dublicated (multiple records that are the same that really
> > should be uniqe) and sometimes in the wrong columns. Even stranger
> > is
> > when data appears in the worng column it only does so for certian
> > records and not others. If I capture the SQL through a debug.prinnt
> > and run it directly in Access I get a clean recordset every time.
> > Does anyone know what the problem might be and how to fix it? Any
> > help would be greatly appreaciated. Thanks.- Hide quoted text -
>
> - Show quoted text -
The copyfromrecord set has always worked. As I have been using/
testing the worksheet more I have noticed this intermitant issue. Here
is my code:
dbpath = ThisWorkbook.Names("dbpath").RefersToRange
dbpass = ThisWorkbook.Names("dbpass").RefersToRange
dbdir = ThisWorkbook.Names("dbdir").RefersToRange
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbpath &
"; Jet OLEDB

atabase Password = " & "'" & dbpass & "'"
Set adoConn = New ADODB.Connection
adoConn.ConnectionString = sConnect
adoConn.Open
rsSpendData.Open sSQL, adoConn, adOpenForwardOnly, adLockReadOnly
If rsSpendData.EOF Then
rsSpendData.MoveFirst
Sheets("Spend Detail").Range("J27").CopyFromRecordset rsSpendData
Else
Sheets("Spend Detail").Range("J27").CopyFromRecordset rsSpendData
End If
I would post the SQL but it is really long. If I put the SQL directly
in an Access Query it always works.