Solved

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

Posted on 2006-11-10
3
300 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
3 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
See if the missing rows contain NULL values.  Excel does not like NULLS.

Leon
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now