Question

Macro in Access2003. SendObject. Write the Subject with report data?

Asked by: oscargarin

ok, i will try to explain.

i have an access databse in office 2003.
i created a Report and a Macro.

the Report contains 'Purchase Order' Number and more info (only 1 PO is displayed).
the Macro open the report, print it to PDF and finally creates an email with 'To', 'CC' and a 'Subject'.

I want that the Macro writes in the email subject the predefined text ('Purchase Order N°')  and add the current 'Purchase Order' number to the subject, so for example, the resulting email Subject must be something like "Purchase Order N° 27".

i was trying to capture some data from the Report to the Macro but i failed! :(

Is possible to do this?

many thanks!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-12-02 at 11:47:43ID21651239
Tags

sendobject

,

access

,

macro

Topic

Microsoft Access Database

Participating Experts
2
Points
110
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SendObject
    I have sent reports from Access using the sendobject command by way of a macro to MSMail, but it doesn't seem to work in Lotus Notes why?
  2. sendObject command
    When using the sendObject command in a macro. How do I add a new OutputFormat for a Form. I want to output as a PDF or a snapshot, preferably a PDF. I can output as a snapshot for a report but not a form. Is there anyway to go into the system registry and allow access to us...
  3. How do you fix a sendobject macro that works inconsistant…
    Hello. I am having trouble with a macro in Access that attaches a document to an email in Outlook. In this database, on one of the forms is a button that runs a macro. The macro pulls the fields of the record that you are on, puts it into a report, and attaches the report t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: nico5038Posted on 2005-12-02 at 11:50:29ID: 15407425

The easy way would be to use VBA instead of a macro.
You can transform a macro to VBA code and then in the sendobject command you can manipulate the Subject with the OrderNumber.

Do you want to use VBA ?

Nic;o)

 

by: oscargarinPosted on 2005-12-02 at 12:14:10ID: 15407645

maybe, if you provide me the instructiones it is fine :)

waiting...

 

by: nico5038Posted on 2005-12-02 at 12:29:43ID: 15407765

OK, right-click the macro and select "Save as".
On the popup form select for the option "As" the "Module" and press OK and [Convert] on the other popup.
Then go to the Modules tab where you find a module for the macro and double-click that to open the code.
Next past that code here so I can advise further.

Nic;o)

 

by: oscargarinPosted on 2005-12-02 at 12:41:58ID: 15407849

Option Compare Database

'------------------------------------------------------------
' Macro_Enviar_Reporte
'
'------------------------------------------------------------
Function Macro_Enviar_Reporte()
On Error GoTo Macro_Enviar_Reporte_Err

    DoCmd.OpenReport "Reporte_Orden_de_Compra_Proveedor", acViewPreview, "", "", acNormal
    DoCmd.PrintOut acPrintAll, 1, 1, acHigh, 1, True
    DoCmd.SendObject acReport, "Reporte_Orden_de_Compra_Proveedor", "SnapshotFormat(*.snp)", "", "rpino@hatch.cl; afigueroa@hatch.cl", "", "Adjunto ""Orden de Compra""", "", True, ""


Macro_Enviar_Reporte_Exit:
    Exit Function

Macro_Enviar_Reporte_Err:
    MsgBox Error$
    Resume Macro_Enviar_Reporte_Exit

End Function


 

by: oscargarinPosted on 2005-12-02 at 12:43:39ID: 15407858

Translation

"Reporte_Orden_de_Compra_Proveedor" this means Purchase Order provider report

 

by: nico5038Posted on 2005-12-02 at 12:49:10ID: 15407903

OK, I'll have to assume the keyfield for your Purchase Order so ket's call it: PurchaseOrderID

Then the code can filter the report using:

    DoCmd.OpenReport "Reporte_Orden_de_Compra_Proveedor", acViewPreview, "", "[PurchaseOrderID]=" & Me.PurchaseOrderID, acNormal

For the subject we need then:

DoCmd.SendObject acReport, "Reporte_Orden_de_Compra_Proveedor", "SnapshotFormat(*.snp)", "", "rpino@hatch.cl; afigueroa@hatch.cl", "", "Adjunto ""Orden de Compra"":" & Me.PurchaseOrderID, "", True, ""

This requires the code to be "behind" the button on your form with the Purchase Order as the Me.PurchaseOrderID refers to a field with the ID on the form.
Just copy/paste all code between the Function and Function End in the code for the print button on your form and it will work OK.

Need more info ?

Nic;o)

 

by: oscargarinPosted on 2005-12-02 at 18:22:18ID: 15409593

i am sorry nico, but i do not have a button in the form.

 

by: nico5038Posted on 2005-12-03 at 01:42:14ID: 15410567

OK, then we need to create a button on the form.
Just select a button from the toolbar on the lefthand side and follow the wizard, chosing a button to trigger a report.
When finished you can select the button with a single click and open the properties popup form.
Under the Events tab you'll see the OnClick event and when you place the cursor in the white field after that a [...] button will appear at the end allowing you to open the code Access generated for the event.
Just replace all code between the "Sub" and "End Sub" commands with your above code.

Clear ?

Nic;o)

 

by: oscargarinPosted on 2005-12-13 at 10:21:28ID: 15476004

hey nico i have created a button in the report (design view), but i just have properties for it, i dont have where to add the code.

are you still available to answer?

 

by: nico5038Posted on 2005-12-13 at 13:03:52ID: 15477382

Yep, but I stated: "we need to create a button on the form."

Nic;o)

 

by: matthews_30Posted on 2005-12-14 at 09:08:35ID: 15483584

i cannt find this:

[Quote nico]
Just select a button from the toolbar on the lefthand side and follow the wizard, chosing a button to trigger a report.
[/Quote]

what wizard, what button?

i have already inseted a button (commandButton) from the toolbox bar, but no wizard found :(

 

by: nico5038Posted on 2005-12-14 at 11:34:35ID: 15484977

When you place a buton a wizard should be activated allowing you to chose different options from a menu.
When the wizard doesn't start you need to click the Wizard button in the toolbox so it looks "pressed".
It has a magicians stick and is just below the Arrow button.

Nic;o)

 

by: matthews_30Posted on 2005-12-15 at 07:53:17ID: 15491025

nico i understand what was happening!

i dont have any "Form" (where you can add buttons with a wizard)

i am working with Tables, Reports and Macros (this does everything).

i execute the send mail function through the SendObject in Macro (Design View), see the following:

i have a link (shortcut) in my hard drive wich is pointiing to a Macro wich has the associated funtions "OpenReport" (Print Preview, Normal), PrintOut (page 1, redirected to a PDF printer), SendObject (Report, Report_Name, Snapshot Format, CC myEmail@myDomain.cl, Subject "mySubject")<-----here is the problem i want to add the "Purchase Order" Number (numero_orden)

i expect you can better understand me now.

hope this help.

 

by: nico5038Posted on 2005-12-15 at 08:43:09ID: 15491490

Not sure or it will work with macro's as I don't use them for their inflexibility.
Try to change:
Subject "mySubject"
into:
Subject "mySubject " & Purchase Order: " & Dlookup("numero_orden","orden","????")
The "numero_orden" must be the fieldname, the "orden" needs to be the tablename, the "????" needs to be the so-called WHERE clause to detect the number asked for.

The best way to "gain control" is however a simple form where the "numero_orden" can be selected before activating the report. A macro can easily be changed into VBA by right-clicking it and use the SaveAs with [Module] as type.

Nic;o)

 

by: matthews_30Posted on 2005-12-16 at 05:31:53ID: 15497387

everything is going fine, but the where clause fails. if i aviod using where it works but the where clause is a little bit complex.

this is the working code for the form (i created a form (frmUltimaOrden) with a label (Label1)), the label is correctly asigning with the last Purchase Order number:

SELECT numero_orden
FROM orden_compra
WHERE (((orden_compra.numero_orden)in (Select max(numero_orden)from orden_compra)));

now, in the module i try to do the following:

Function Macro_Enviar_Reporte()

Dim varX As Variant
'varX = DLookup("[numero_orden]", "orden_compra") 'this works. No 'Where' clause
varX = DLookup("[numero_orden]", "orden_compra", [orden_compra] = " & Forms![frmUltimaOrden]![Label1.Caption]) this is not working!!!

the error displayed when i try to use the form is:

"Microsoft Acces can't find the form 'frmUltimaOrden' referref in a macro expresion or a visual basic code", please note that i copy/paste the bane if the form.

in brief, i need to get the last "purchase order" number generated and put it in 'varX' or any variable.

hope this helps.

 

by: nico5038Posted on 2005-12-16 at 06:05:47ID: 15497559

Try:
varX = DLookup("[numero_orden]", "orden_compra", [orden_compra] = '" & Forms![frmUltimaOrden]![Label1.Caption] & "'")

Nic;o)

 

by: matthews_30Posted on 2005-12-16 at 06:28:08ID: 15497661

it displays an error:

Compile error: Syntax error

:(

 

by: nico5038Posted on 2005-12-16 at 10:25:25ID: 15499559

OK, try:

varX = DLookup("[numero_orden]", "orden_compra", [orden_compra] = '" & Forms![frmUltimaOrden]![Label1].[Caption] & "'")
Or when the orden_compra is a number:
varX = DLookup("[numero_orden]", "orden_compra", [orden_compra] = " & Forms![frmUltimaOrden]![Label1].[Caption] )

Nic;o)

 

by: oscargarinPosted on 2005-12-23 at 07:24:18ID: 15542610

finally everything failed, though i made it work with the following workaround so i decide to share it to everybody learns (that is the way we help to build a better world :)

i create a macro with an action RunCode to call a module with a funtion called "Macro_Enviar_Reporte ()", here is the module code:

Function Macro_Enviar_Reporte()
On Error GoTo Macro_Enviar_Reporte_Err

    Dim Rst As DAO.Recordset
    Dim ultima_orden As String
   
        Set Rst = CurrentDb.OpenRecordset("Select numero_orden FROM orden_compra Where  (((orden_compra.numero_orden)in (Select max(numero_orden)from orden_compra)))")
        If Rst.NoMatch Then
            'MsgBox "No hay Registros según criterio"
        Else
            'MsgBox "El nombre de la ultima orden es: " & Rst("numero_orden")
            ultima_orden = Rst("numero_orden")
        End If
        Rst.Close
        Set Rst = Nothing

    DoCmd.OpenReport "Reporte_Orden_de_Compra_Proveedor", acViewPreview, "", "", acNormal
    DoCmd.Maximize
    DoCmd.RunCommand acCmdZoom100
    'pregunta = MsgBox("Desea revisar la Orden de Compra?", vbYesNo, "Revisión Orden de Compra")
    'If pregunta <> 6 Then
        DoCmd.PrintOut acPrintAll, 1, 1, acHigh, 1, True
        DoCmd.SendObject acReport, "Reporte_Orden_de_Compra_Proveedor", "SnapshotFormat(*.snp)", "", "afigueroa@hatch.cl; rpino@hatch.cl", "", "Adjunto Orden de Compra N° " & ultima_orden, "", True, ""
        DoCmd.RunCommand acCmdExit
    'End If

Macro_Enviar_Reporte_Exit:
    Exit Function

Macro_Enviar_Reporte_Err:
    MsgBox Error$
    Resume Macro_Enviar_Reporte_Exit

End Function

hope this help!

 

by: oscargarinPosted on 2005-12-23 at 07:26:06ID: 15542625

so the points will go to Nic;o because of his patiently work with me!

thanks a lot Nic;o, you really help me!

honestly,

Oscar Garin.

 

by: nico5038Posted on 2005-12-23 at 09:23:18ID: 15543429

Couldn't have done it better Oscar, especially the "No hay Registros según criterio" is far beyond my knowledge :-)

Success with the application and happy holidays !

Nic;o)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...