How would I set up via DAO to pull an Access Query into Excel? The reason I am wanting to use DAO is because in the query there is a LARGE memo field, and any other way I try to bring in the query it cuts off the Memo field.
How would I set up via DAO to pull an Access Query into Excel? The reason I am wanting to use DAO is because in the query there is a LARGE memo field, and any other way I try to bring in the query it cuts off the Memo field.
Last edited by jo15765; 01-19-2012 at 11:54 AM.
Here is a very simple example
It requires you to set a reference to the DAO library.![]()
Please Login or Register to view this content.
Good luck.
The query string..
Could I pull that directly from the SQL view from Access?
Just use the name of the view/query.
That imports the data, but it is still cutting my memo field off...
Assuming you are not grouping on the memo field in your query, I suspect you may have to loop through the data rather than using CopyFromRecordset. GetRows may be an option, but you need to be aware that the resulting array is transposed from what you might expect.
I am not grouping on anything. The only parameter other than "Not Null" I am using is, I am sorting Date descending. How would I loop through the data?
Last edited by jo15765; 01-18-2012 at 10:34 AM. Reason: Used wrong Term -- Am not grouping only sorting
Roughly
or populate an array with the data and write that out to the sheet. If you have a lot of data it will be much faster.![]()
Please Login or Register to view this content.
I think the largest that the query gets is 200 records.
Where would I add the code you posted above?
Last edited by jo15765; 01-18-2012 at 10:38 AM.
What do you mean: is not visible ? or 'stops the importing process' ?it cuts off the Memo field
Excel only shows a limited amount of characters in a cell, while that cell contains much more.
You can check that using msgbox len(sheet1.cells(1))
It replaces the
line.![]()
Please Login or Register to view this content.
The memo field may actually contain 500 characters, while Excel only imports 250 (of course those numbers are not accurate just using for examples sake)
The way I have been importing the data, is copying from the query, right clicking in Excel, choosing paste special, then selecting CSV and it pastes all characters from the Memo field.
They should both be Long data types. Apologies - I omitted the declaration lines from the top of my code sample.
I get a debug error of invalid operation on
![]()
Please Login or Register to view this content.
Ah - remove that line - I forgot I was using a forward only recordset.
Argh, it's still not pulling inn all the data from my memo field in access.
I don't think you can loop through datasets with this:
Try changing it to:![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
Does the query do anything to the memo field other than return it?
oops was looking at the wrong page :s
Ah right ok, my DAO is pretty limited I use ADO
Should be the same in ADO. If you use a firehose cursor for example, it's quick but you can only iterate the records once.
It only returns the memo field. The only thing that could be considered quirky is the fact that I have date sorted descending.
I would probably need to see the database but it may also be a limitation of Office 2000, which I do not have.
@kyle123
In other news, your avatar has brightened my day considerably. A little like Baloo after a serious diet.
Just noticed: thank you for the rep, by the way.
Last edited by OnErrorGoto0; 01-18-2012 at 12:53 PM.
@OnError brightens mine too, it frequently needs brightening
This gave me the full text of the memo field:
![]()
Please Login or Register to view this content.
I am getting Variable Not defined on
![]()
Please Login or Register to view this content.
Try changing it to 3
Now I am getting a debug error of Uknown is not a valid path Highlighting the cn.Open
Just to make sure I have it correct...
![]()
Please Login or Register to view this content.
Last edited by jo15765; 01-18-2012 at 03:57 PM. Reason: Forgot the closing code tag
You need to change the file path to where your db is as well as the name of your db
desired result with:
or using 'early binding':![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
Last edited by snb; 01-18-2012 at 04:38 PM.
I had the Default Directory mapped wrong. I forgot one stipulation...how would I add into it where Date is Not null?
SNB -- the copy recordset option would always cut off my memo field in the database, so at least the times I have tested it, option would not work.
You didn't test my code, because I got the full 'comment' from your database: 475 characters long, what will be shown in the messagebox.
The crux is in adding the 3 in the instruction 'open' of the recordset.
![]()
Please Login or Register to view this content.
Last edited by snb; 01-18-2012 at 05:47 PM.
I get a compile error of variable not defined on the co1 line of your code snb
Yes, of course: remove 'Option Explicit'
It's still cutting off the data in my memo field using that code.
So how come ? cfr. the attachment.
And what is being shown in the message Box ?
The message box shows
14
Troyb@nist.gov
what is cfr the attachment?
That's very peculiar that my sample I provided works, but when I try to run it on my real database it doesn't....
check in the real database what is the content of the 'comment' field in the first record.
I am not sure what you mean by content...It is a comment, just a long typed out expression similar to what I provided in the sample database that was uploaded.
I just figured out what the problem is. In the query it is set up to show: FullComments: "Customer Comments:" & [comment] And it names the field FullComments (which can drop I don't care about that) and then it appends Customer Comments: to the beginning of the actual comments in the database. I need to keep Customer Comments: as a prefix for the comment field, but it is clearly messing up the DAO/ADO import. Any suggestions on a workaround for this?
I just wrote a function that would append "Customer Comments:" To the beginning of that column, so that is figured out now. The problem I have now is that Rows 1 and 2 are header rows, and each of the codes provided start pulling the data onto Row 2. What would need to be modified so that data does not begin until Row 3?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks