Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Use DoCmd.SendObject to Send an Excel .xls with Filename Based on an Order Number

Posted on 2008-10-01
9
Medium Priority
?
410 Views
Last Modified: 2013-11-27
Hi Experts!

I have an Access 2003 Db that uses DoCmd.SendObject to send a vendor an order based on a query called "Qry_Order". This works great, but it would be nice if the filename was unique to each order . As it is now, the attached .xls file is always named after the query so: "Qry_Order.xls".

There is an order number that I would like to pass to create the filename from. It is called "PR_Number" and looks like "PR1058", for example and this would, ideally be passed to create "PR1058.xls"  I have no idea how to do this. I have a combo box I can reference for the PR_Number. Just don't know it it can be done.

Here is the DoCmd statement I have now:
DoCmd.SendObject acSendQuery, "Qry_Order", "Microsoft Excel", _
myVendor, _
, , StrSubject

Thanks,

Kevin
0
Comment
Question by:k_smee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 22616254
Try this:
Use the TransferSpreadsheet method to export the query to a spreadsheet with the name you want to use then use the SendObject method to send the spreadsheet to the vendor.
0
 

Author Comment

by:k_smee
ID: 22616674
I got the DoCmd.TransferSpreadsheet to make the file in my C:\Temp folder, but I don't see that the DoCmd.SendObject method has provision to send anything other than an Access object like a query, table, etc...Am I missing something?
0
 
LVL 16

Accepted Solution

by:
Chuck Wood earned 500 total points
ID: 22616835
You are correct.

You can use the attached code together with the attached class module (change txt to cls and import) to email your spreadsheet.

Public Sub SendEmail()
    Dim cls As New clsSendEmail, blnSent As Boolean
    blnSent = cls.Email("someone@somewhere.com", "Subject", "Body", , "ExcelPathAndName")
    If Not blnSent Then MsgBox "The Email Failed", vbInformation, "Email Failed"
End Sub

Open in new window

clsSendEmail.txt
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:k_smee
ID: 22619887
Thanks! I'll give it a shot in the morning. The db is at work..
0
 

Author Comment

by:k_smee
ID: 22624417
This works great. Is there a way to have it pop up the Outlook mail object to pick recipients or do i need to hard code them? Some of my users like to be able to add other recipients. Thanks! Kevin
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 22624500
You can use an InputBox or a UserForm to let them add recipients. Opening the mail item is something I haven't done before.
0
 

Author Comment

by:k_smee
ID: 22636751
I figured out how to do the display object before sending. I just added:
outMsg.Display True

This is right before the .Send command.
Thanks for all the help !
0
 

Author Closing Comment

by:k_smee
ID: 31501992
Excellent help on this one, Thanks!
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 22636788
I am very glad you found the answer. And thank you for sharing it with the rest of us. Thank for the kind words and the high grade. Good luck on your project.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question