Ok, for the code, just use the wizard. It allows you the option to "send a
report through email". It will create the basic code tied to the button.
You can go back into the vba code and modify the line to include an email
address, subject, etc.
I don't think you can apply a filter in vba code when sending a report via
email. Maybe someone else will jump in. What I would do is simply apply
the filter to my query upon which the report is based. So...
Your new report (we'll call it "Ticket-Email") should be built on a saved
query (we'll call it "qryTicketEmail"). This query should have a column for
TicketNumber or some other unique field. You should tell the query to only
pull for one ticket (the one currently on your open form). To do so, change
your criteria to something like the following...
=[Forms]![Your FormNameHere]![YourTicketFieldFromTheFormHere]
What this will do is...
When you run the Ticket-Email report the query tht pulls in the info will go
out and look at your form (which must be opened and must have a valid ticket
displayed) and will produce the report ONLY for the ticket being displayed.
To email the report, your button will open the report and add it to an
email. You can fill in the various options and click your send button.
NOW for a few error checks....
The code that the button writes will do what I said above. Typically, the
wizard writes a bunch of extra stufff to do this. You could replace the
whole event with the code I provide below...
You may want to add a check to make sure the form is actually displaying a
record. Also, if the person is in the process of making changes or adding
that record, then you will have trouble. Here is the code to do that...
Private Sub cmdEmailReport_Click()
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to
print
MsgBox "Select a record to print"
Else
DoCmd.SendObject acReport, "Ticket-Email", , , , , "Subject
of email here", "Any Message Text Here"
End If
End Sub
--
Rick B
Roxanne said:
Ok I have a report with the data I want included in the report. I added a
button to my form, but now I'm stuck on how to write a filter. I've been
searching everywhere on the basic of how to write a filter to send the
current trouble ticket number and haven't been able to find out the exact
steps to writing a filter. Also, I have no idea how to write VB code for the
Docmd.SendObject you mentioned. I'm totally lost on where you write the code
to email the ticket. Basically, I'm totally lost on these two points. I
know if I can see an example of what I have to do I can put the code in, and
probably get this to work, but knowing how to do it off the top of my head I
don't. Do you know any place that will show basic steps in writing a filter
and the VB code?
Thanks so much for your patience and help - I do appreciate it.
Roxanne