I've recently received feedback from thread701-1198915 (thanks to BoxHead) on how to export an Access table to excel using a command button. Is there also a way, with VB script, to not only place the excel file in a designated directory on a PC, but also, when exported, it opens a new outlook email and attaches it to the new email? Below is the code I've used so far to export an Access table to an excel spreadsheet:
CODE
Private Sub Command0_Click()
Dim db As DAO.Database, rs As DAO.Recordset, str1Sql As QueryDef, strCrt As String, strDt As String
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT DISTINCT SR FROM tblPipeline ORDER By SR;")
strDt = Format(Month(Date), "00") & Format(Day(Date), "00") & Format(Year(Date), "00")
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
strCrt = rs.Fields(0)
Set str1Sql = db.CreateQueryDef("rpt_" & strCrt, "SELECT tblPipeline.* FROM tblPipeline WHERE tblPipeline.SR = '" & strCrt & "';")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "rpt_" & strCrt, "C:\Documents and Settings\John\My Documents\SR_Report_" & strDt & ".xls", True
DoCmd.DeleteObject acQuery, "rpt_" & strCrt
rs.MoveNext
Loop
End Sub
CODE
Private Sub Command0_Click()
Dim db As DAO.Database, rs As DAO.Recordset, str1Sql As QueryDef, strCrt As String, strDt As String
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT DISTINCT SR FROM tblPipeline ORDER By SR;")
strDt = Format(Month(Date), "00") & Format(Day(Date), "00") & Format(Year(Date), "00")
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
strCrt = rs.Fields(0)
Set str1Sql = db.CreateQueryDef("rpt_" & strCrt, "SELECT tblPipeline.* FROM tblPipeline WHERE tblPipeline.SR = '" & strCrt & "';")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "rpt_" & strCrt, "C:\Documents and Settings\John\My Documents\SR_Report_" & strDt & ".xls", True
DoCmd.DeleteObject acQuery, "rpt_" & strCrt
rs.MoveNext
Loop
End Sub