maybe, if you provide me the instructiones it is fine :)
waiting...
Main Topics
Browse All Topicsok, 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.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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)
Option Compare Database
'-------------------------
' Macro_Enviar_Reporte
'
'-------------------------
Function Macro_Enviar_Reporte()
On Error GoTo Macro_Enviar_Reporte_Err
DoCmd.OpenReport "Reporte_Orden_de_Compra_P
DoCmd.PrintOut acPrintAll, 1, 1, acHigh, 1, True
DoCmd.SendObject acReport, "Reporte_Orden_de_Compra_P
Macro_Enviar_Reporte_Exit:
Exit Function
Macro_Enviar_Reporte_Err:
MsgBox Error$
Resume Macro_Enviar_Reporte_Exit
End Function
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_P
For the subject we need then:
DoCmd.SendObject acReport, "Reporte_Orden_de_Compra_P
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)
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)
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.
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","or
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)
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_ord
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]![La
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.
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("S
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_P
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_P
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!
Business Accounts
Answer for Membership
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)