Return Focus to Access after Excel Export

A

Alt255

This is something thats been bothering me for a while. I have a VBA
subroutine that takes a recordset and pastes the data to a blank Excel
worksheet. Then Access gives a message that it's complete.
The problem is that the active window is the excel worksheet, and not
the access form. Anyone know how to return the focus back to Acess
after the copyfromrecordset is complete?
 
A

Alt255

Could you post your code so we can try and help.
--
Hope this helps,

Daniel Pineaulthttp://www.cardaconsultants.com/
For Access Tips and Examples:http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.





- Show quoted text -

The code is too long, but here is a trimmed psuedo code

set recordset1 = database.querydefs(Trade Query")

set xlapp = excel.application
xlapp.displayalerts = false
xlapp.visible = true
xlapp.usercontrol = true
set xlwb = xlapp.workbooks("C:\Excel Template.xls")
set xlws = xlwb.worksheets("sheet1")
xlws.select
xlws.cells(10,1).copyfromrecordset recordset1
xlws.close
recordset1.close
msgbox("Done")

It is the msgbox done I want the user to see, but the active window is
the excel file. Once I go to Access, I will see the message, but I
want the code to automatically return to access once the recordset has
been copied, so the user knows that it is done. Right know some of the
users are just staring at excel not realising that the data exports
are done.
 
A

Alt255

The code is too long, but here is a trimmed psuedo code

set recordset1 = database.querydefs(Trade Query")

set xlapp = excel.application
xlapp.displayalerts = false
xlapp.visible = true
xlapp.usercontrol = true
set xlwb = xlapp.workbooks("C:\Excel Template.xls")
set xlws = xlwb.worksheets("sheet1")
xlws.select
xlws.cells(10,1).copyfromrecordset recordset1
xlws.close
recordset1.close
msgbox("Done")

It is the msgbox done I want the user to see, but the active window is
the excel file. Once I go to Access, I will see the message, but I
want the code to automatically return to access once the recordset has
been copied, so the user knows that it is done. Right know some of the
users are just staring at excel not realising that the data exports
are done.- Hide quoted text -

- Show quoted text -

I finally figured it, use:
AppActive "<<Name of the Running Program>>"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top