?
Solved

Retreiving data from an Access Database using Microsoft Excel and VB macros

Posted on 2006-11-10
3
Medium Priority
?
307 Views
Last Modified: 2013-12-25
I've recently been given a project to fix which pulls data from tables in an Access database and pastes them into an Excel worksheet.

The problem I'm having is that it only copies some of the data.  There are 1700 records in the table of the databse but when pasted into Excel only pastes around 1500 rows.  The following code is used to import the cases but there doesn't appear to be any set range that stops it importing all of the records.

    '=================== Import Cases from Access ======================
    Set rst = New ADODB.Recordset
    rst.CursorLocation = adUseServer
   
    rst.Open Source:="Table_Cases", ActiveConnection:=cnn, CursorType:=adOpenDynamic, LockType:=adLockOptimistic, Options:=adCmdTable
   
    Worksheets("Escalation Workspace").Select 'Activate
         
    Range("A3").CopyFromRecordset rst


My main question would be is there any limit to the amount of data that can be pulled from Access?

Many thanks
0
Comment
Question by:ward20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 1500 total points
ID: 17913471
Im not aware of any limits in this
as a test can u try this

first, perform a SELECT * FROM Table_Cases
it shouldnt make a different but try it anyway
then verify the number of records using recordcount property



rst.Open Source:="SELECT * FROM Table_Cases", ActiveConnection:=cnn, CursorType:=adOpenDynamic, LockType:=adLockOptimistic, Options:=adCmdTable

'now add ths
msgbox "Number of Records " & rst.RecordCount


What value do u get in the msgbox?
If u get -1, then try this

rst.MoveLast
rst.MoveFirst
msgbox "Number of Records " & rst.RecordCount



Now what value do u get?


Next, try a looping method
Im trying to remember exact syntax of checking it but its something like this
Paste 1000 rows at a time


dim lRows as long

lRows = 3

do while rst.EOF = False
    Range("A" & lRows).CopyFromRecordset rst, 1000
    lRows = lRows + 1000
loop

0
 
LVL 11

Expert Comment

by:leclairm
ID: 17914965
This is the CopyFromRecordset syntax.

returnValue = SomeRange.CopyFromRecordset(Recordset, MaxRows, MaxColumns)

CopyFromRecordset returns the number of rows copied.  So you can assign it to a variable to compare against the number of records in your recordset.

Is this a new excel sheet or are you pasting it into an existing one??
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 17916704
See if the missing rows contain NULL values.  Excel does not like NULLS.

Leon
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question