Solved

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

Posted on 2006-11-10
3
304 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 500 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

Industry Leaders: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 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