T
TheNovice
Good morning all,
I have a quick Question. I need to send a table out in Excel, I have the
code set up but I need to filter it out to equal what is on the table.
I am recycling some old code that uses a report but the format is not what
we are looking for.
Here is a sample of the code: can someone PLEASE HELP!
Private Sub Form_Open(Cancel As Integer)
Dim db As Database
Set db = CurrentDb
Dim rc As Recordset
Dim stToName As String
Dim strRSM As String
Dim strSubj As String
Dim strBody As String
Dim strFileName As String
Dim rpt As TableDef
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryWinFull"
DoCmd.OpenQuery "qryWinFullTable"
DoCmd.SetWarnings True
'DoCmd.OpenQuery "WinFull", acViewDesign
'DoCmd.OpenTable Winfull, acViewNormal, acEdit
'Set rpt = Table!Winfull
'rpt.Visible = False
Set rc = db.OpenRecordset("RSM Table")
If Not (rc.BOF Or rc.EOF) Then
rc.MoveFirst
Do Until rc.EOF
stToName = rc!emailid
strSubj = "Tomorrow's orders within 20% of Full Pallet"
strBody = "Please find the Enclosed Report for Tomorrow's orders
within 20% of Full Pallet"
strRSM = rc![CMRSM#]
strFileName = "c:\commun\Within 20 Percent of Pallet for " +
strRSM + ".xls"
BuildExcelSht stToName, strSubj, strBody, strFileName, strRSM
'Set rpt = Table!Winfull
rc.MoveNext
Loop
End If
DoCmd.SetWarnings False
DoCmd.Close acQuery, "qryWinFullTable"
Exit Sub
End Sub
Sub BuildExcelSht(stToName As String, strSubj As String, strBody As String,
strFileName As String, strRSM As String)
'rpt.Filter = "RGN = " & Chr(34) & stDSM & Chr(34)
'DoCmd.SendObject acReport, stDocName, "Snapshot Format", stToName,
stCCName, , stSubjLine, stBody, False
DoCmd.OutputTo acOutputTable, "Winfull", "Microsoft Excel", strFileName
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "(e-mail address removed)"
objEmail.To = stToName
'objEmail.Cc = stCCName
objEmail.Subject = stSubjLine
objEmail.Textbody = stBody
objEmail.AddAttachment strFileName
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"xxxxxx.xxxxx.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Exit Sub
End Sub
I have a quick Question. I need to send a table out in Excel, I have the
code set up but I need to filter it out to equal what is on the table.
I am recycling some old code that uses a report but the format is not what
we are looking for.
Here is a sample of the code: can someone PLEASE HELP!
Private Sub Form_Open(Cancel As Integer)
Dim db As Database
Set db = CurrentDb
Dim rc As Recordset
Dim stToName As String
Dim strRSM As String
Dim strSubj As String
Dim strBody As String
Dim strFileName As String
Dim rpt As TableDef
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryWinFull"
DoCmd.OpenQuery "qryWinFullTable"
DoCmd.SetWarnings True
'DoCmd.OpenQuery "WinFull", acViewDesign
'DoCmd.OpenTable Winfull, acViewNormal, acEdit
'Set rpt = Table!Winfull
'rpt.Visible = False
Set rc = db.OpenRecordset("RSM Table")
If Not (rc.BOF Or rc.EOF) Then
rc.MoveFirst
Do Until rc.EOF
stToName = rc!emailid
strSubj = "Tomorrow's orders within 20% of Full Pallet"
strBody = "Please find the Enclosed Report for Tomorrow's orders
within 20% of Full Pallet"
strRSM = rc![CMRSM#]
strFileName = "c:\commun\Within 20 Percent of Pallet for " +
strRSM + ".xls"
BuildExcelSht stToName, strSubj, strBody, strFileName, strRSM
'Set rpt = Table!Winfull
rc.MoveNext
Loop
End If
DoCmd.SetWarnings False
DoCmd.Close acQuery, "qryWinFullTable"
Exit Sub
End Sub
Sub BuildExcelSht(stToName As String, strSubj As String, strBody As String,
strFileName As String, strRSM As String)
'rpt.Filter = "RGN = " & Chr(34) & stDSM & Chr(34)
'DoCmd.SendObject acReport, stDocName, "Snapshot Format", stToName,
stCCName, , stSubjLine, stBody, False
DoCmd.OutputTo acOutputTable, "Winfull", "Microsoft Excel", strFileName
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "(e-mail address removed)"
objEmail.To = stToName
'objEmail.Cc = stCCName
objEmail.Subject = stSubjLine
objEmail.Textbody = stBody
objEmail.AddAttachment strFileName
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"xxxxxx.xxxxx.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Exit Sub
End Sub