Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attach query as excel file 1

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
Below is the code I am currently using to send email from
Access. I would like to attach a query as an excel file but
do not know how to using this code. Can anyone offer suggestions
as to how to accomplish this with the below code?

Code:
Private Sub StatsNewPartsQryFrm_Click()

       Dim O As Outlook.Application
       Dim m As Outlook.MailItem
       Dim toEmail1 As String
       Dim toEmail2 As String
       Dim ccEmail1 As String
       Dim ccEmail2 As String
       Dim ccEmail3 As String
       Dim bccEmail1 As String
       Dim SL As String, DL As String
       SL = vbNewLine
       DL = SL & SL

Set O = CreateObject("Outlook.Application")
Set m = Outlook.CreateItem(0)
'toEmail1 = DLookup("ActualName", "ChangeFormUserNameTbl", "LoginName='" & GetCurrentUserName() & "'")

ccEmail1 = ""
ccEmail2 = ""
ccEmail3 = ""
bccEmail1 = ""
    
m.To = "aldeb@chpl.net"
m.CC = ""
m.BCC = ""
m.Subject = "New Part Query."
m.Body = "Please see attached Excel File for New Part Qry by Date Range." & DL & _
       DLookup("ActualName", "ChangeFormUserNameTbl", "LoginName='" & GetCurrentUserName() & "'")
       
m.Display

End Sub
 
Save(OutputTo) query as excel then attach with the mail

Code:
m.Attachments.Add(.....)
Later you can delete the excel file.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Thanks for your input.

I am not sure what you mean. I want Access to automatically
send the query as an excel file. How do I apply Save(OutputTo) query as excel.
 
This query will be based on a date range And can be ran several times a day with different date ranges.
 
I guess to put it better, I am wanting to output the query as
as an excel file and attach it at the same time using the email
code I have above. I know I can switch to another type email
code but I am hoping to avoid that.
 
Zameer,

Can you explain a little better how to use what you sent me earlier??
 
Have a look in the help file for "OutputTo" or "TransferSpredSheet"
It will explain you how to save a query/table as excel file.

I am not at my desk now to show a working code.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Thanks for your help. I think I have it now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top