Data from Access to Excel

Brawn

New Member
Joined
Aug 20, 2004
Messages
3
Is there a way to export specific data points in a query to specific cells in various excel worksheets named with one of the data points?

Thanks in advance for the help.

Brent
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Not much detail to go on :)

Here is some code that should point you in the right direction.

Shout back if you need more specific help.

Code:
Sub XlExport()
Dim appXL As Excel.Application
Dim wk As Excel.Workbook
Dim rst As Recordset
Set appXL = New Excel.Application
Dim xxx As Variant
' The path/name of the XL file  goes here.
Set wk = appXL.Workbooks.Open("C:\a 2\temp.xls")

'open Query/table here
Set rst = CurrentDb.OpenRecordset("zztemp2", dbOpenForwardOnly)

wk.Worksheets("sheet1").Range("a1") = rst!Field1
rst.MoveNext
wk.Worksheets("sheet1").Range("a2") = rst!Field2

'clean up behind yourself and quit excel
Set rst = Nothing
wk.Close (True)
Set wk = Nothing
appXL.Quit
Set appXL = Nothing

End Sub


Edit
I forgot to add that you will need to make a reference to do this.
in any module go Tools>Reference... and scroll down select the "Microsoft Excel Object Libary"


HTH

Peter
 
Upvote 0
Two things. More examples of technique.

http://www.mvps.org/access/modules/mdl0035.htm

And, you forgot something bat. This line needs to be included in your closing/cleanup segment at the end.

Code:
appXL.UserControl = True

I believe this is the post where I first found my answer/explanation of why this is mandatory.

http://www.mrexcel.com/board2/viewtopic.php?t=76988&highlight=usercontrol

Nice work through all the other posts - you've been hammering out the correct answers for the last couple days and only leaving the itty bitty stuff for the rest of us. :pray:

Mike
 
Upvote 0
I have no problems getting out of Excel with out using UserControl usink Win2K/O2K but I will try to add it to other examples in case it is a version specific problem.

Help implies that it should not be a problem as it releases XL when the last reference to it is released.
If this property is False, Microsoft Excel quits when the last object in the session is released.

Access is fun, biggest problem I usualy have is deciding what the question is actualy asking :)

The other problem I get is ammount of time I can commit, as projects come and go I may be in and out all day or not here for weeks at a time, but I like to answer when I can, as solving other ppl's problems often gives me a head start when something simmilar crops up for me.

Peter

Peter
 
Upvote 0
Sorry for the delay in response, but this board has been great....Thanks for all of the help. What you provided should get me off in a new direction.

Brent
 
Upvote 0
I'm also W2K/O2K - and I get it every time. Primary visible symptom is it'll close the visible window, but if you check task manager, you'll see a running instance of Excel.

I'm pretty sure my installation is current - have tossed my employers standard install in favor of O2Kdeveloper off my personal CD's.

Here's a test question for ya Bat. What's *your* default property value for it? Could yours be defaulted to true?

Mike
 
Upvote 0
nope, it shows as false when I test it. I check taskmanager to make sure there are no instances and there is no XL.

Only other thought I have on this is whether there is a difference in using early/late binding?

And I was slightly misleading with versions as I have W2K / O2K but with A97 and just to add to the confusion I have also had AXP installed to help with ppl who have had their pc's upgraded.

peter
 
Upvote 0
Really don't know - I'm using the same technique as yours above/early.
I'd be curious as to the culprit - may try copying your precise sample in a fresh mdb just to see if it preforms any differently.

I'm wondering if it's a limited subset of the actions you can do that's triggering the save/close issue for me.

Mike
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,747
Members
449,335
Latest member
Tanne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top