Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 47
Hide vba in gp 7 104
vbModal 12 57
Advice in Xamarin 21 96
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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