G
Guest
Hiya.
Things are finally starting to work for me... whoopie. But I need a bit of help in something:
I am getting a load of recordsets in Access, opening a workbook and pasting in the recordsets and then emailing the workbook.
2 problems:
1. With my method, when the procedure runs it goes over to Excel to perform the copyrecordset etc. I need the focus to stay on the Access database when it is doing all the work. How can I do this (my code is below).
2. I have something (XLRunning) to assess whether Excel was running before the procedure was done - if it wasn't I want to quit Excel - but I don't know how to do this without referencing my excel object (which will have already been closed). Can you help? (notes on code below).
Code:
Set XLObject = GetObject(TargetFile)
With XLObject
.Application.Visible = True 'If I don't make visible, copyrecordset fails
.Parent.windows(1).Visible = True
.Sheets(2).Range("A9").CopyFromRecordset rstref
.Sheets(3).Range("A9").CopyFromRecordset rstpreop
.Sheets(4).Range("A9").CopyFromRecordset rstbl
.Sheets(5).Range("A9").CopyFromRecordset rstip
.Sheets(6).Range("A9").CopyFromRecordset rstpostop
End With
XLObject.SendMail patrepemail, "RPH Patient Report"
XLObject.Close SaveChanges:=True
If XLRunning = False Then XLObject.Application.Quit 'This won't work coz XLObject is already closed
Thanks for any suggestions.
Basil
Things are finally starting to work for me... whoopie. But I need a bit of help in something:
I am getting a load of recordsets in Access, opening a workbook and pasting in the recordsets and then emailing the workbook.
2 problems:
1. With my method, when the procedure runs it goes over to Excel to perform the copyrecordset etc. I need the focus to stay on the Access database when it is doing all the work. How can I do this (my code is below).
2. I have something (XLRunning) to assess whether Excel was running before the procedure was done - if it wasn't I want to quit Excel - but I don't know how to do this without referencing my excel object (which will have already been closed). Can you help? (notes on code below).
Code:
Set XLObject = GetObject(TargetFile)
With XLObject
.Application.Visible = True 'If I don't make visible, copyrecordset fails
.Parent.windows(1).Visible = True
.Sheets(2).Range("A9").CopyFromRecordset rstref
.Sheets(3).Range("A9").CopyFromRecordset rstpreop
.Sheets(4).Range("A9").CopyFromRecordset rstbl
.Sheets(5).Range("A9").CopyFromRecordset rstip
.Sheets(6).Range("A9").CopyFromRecordset rstpostop
End With
XLObject.SendMail patrepemail, "RPH Patient Report"
XLObject.Close SaveChanges:=True
If XLRunning = False Then XLObject.Application.Quit 'This won't work coz XLObject is already closed
Thanks for any suggestions.
Basil