Hi Christopher,
The scenario I am looking at requires that when we fill out the form, prior
to saving the record, we need to have an email of that current form sent to a
group.
You need to commit the save operation first if this is a new record. Try
this (I'm assuming the name of your report is Operations Update):
If Me.Dirty = True Then
Me.Dirty = False
End If
DoCmd.OpenReport "Operations Update", acPreview, _
WhereCondition:="ID = " & Me.ID
WhereCondition = "ID = " & Me.ID (Is this the proper command?)
Yes, however, now that I look at it again, I gave you the form for a numeric
primary key field. If your primary key is text, then use this instead:
DoCmd.OpenReport "Operations Update", acPreview, _
WhereCondition:="ID = " & Chr(34) & Me.ID & Chr(34)
This is what I created based on what you have provided.
stDocName = "Operations Update" (The database the form resides in)
Though this still pulls the full report, are we missing something?
The SendObject method does not include a WhereCondition arguement.
Therefore, you'll have to approach this a little differently. Create a query
that includes all the fields that you want. Add the primary key field. Add
criteria to the primary key field like this:
=Forms![FormName]![ID]
For example, in the Northwind sample database, the SQL statement for a query
might look like this:
SELECT Customers.*
FROM Customers
WHERE CustomerID=[Forms]![Customers]![CustomerID];
You would then set this query as the recordsource for your report. Of
course, the form must be open in preview mode (not design view) when you run
this query. You must be sitting on a record that has already been committed
(saved) to the database. You can either have fields on the form for the
various e-mail addresses (To, CC & BCC), the subject, and the message text,
or you can hard code these values if you want. The code below includes both
methods as an example, with the fields method commented out. I am also
exporting the results of the report to the Microsoft Snapshot format:
Option Compare Database
Option Explicit
Private Sub cmdSendReport_Click()
Dim strTo As String
Dim strCC As String
Dim strBCC As String
Dim strSubject As String
Dim strMessage As String
'strTo = Nz(Me.txtToEmailAddress, "")
'strCC = Nz(Me.txtCCEmailAddress, "")
'strBCC = Nz(Me.txtBCCEmailAddress, "")
'strSubject = Nz(Me.txtSubject, "")
'strMessage = Nz(Me.txtMessage, "")
strTo = "(e-mail address removed)"
strCC = "(e-mail address removed); (e-mail address removed)"
strBCC = "(e-mail address removed)"
strSubject = "Latest Results"
strMessage = "Here are the latest customer sales results. " _
& vbCrLf & vbCrLf _
& "In order to view the attached report, you must have " _
& "the Microsoft Snapshot Viewer utility installed. You can " _
& "download a free copy from Microsoft at this address:" _
& vbCrLf & "
http://support.microsoft.com/?id=175274" _
& vbCrLf & vbCrLf & "Sincerely," & vbCrLf & "Christopher Crettol"
DoCmd.SendObject acReport, "Operations Update", _
OutputFormat:=acFormatSNP, _
To:=strTo, CC:=strCC, BCC:=strBCC, _
Subject:=strSubject, MessageText:=strMessage,
EditMessage:=True
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdSendReport_Click..."
Resume ExitProc
End Sub
Tom
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
:
Hello Tom,
Gordon and I are both working on this project. First let me thank you for
the information you have already provided; it has helped out greatly.
I was able to set up the "DoCmd" okay and created the email command that I
need, though I have a question regarding the "WhereCondition" statement.
The scenario I am looking at requires that when we fill out the form, prior
to saving the record, we need to have an email of that current form sent to a
group.
I believe I understand your thinking on how to the "WhereCondition" should
work. If my "PKFieldName" is "ID" Then my "& Me.PKFieldName" would be "&
Me.ID"":
WhereCondition = "ID = " & Me.ID (Is this the proper command?)
This is what I created based on what you have provided.
stDocName = "Operations Update" (The database the form resides in)
DoCmd.SendObject acPreview, stDocName (Sends a preview of the database
report)
WhereCondition = "ID = " & Me.ID (Specifies a particular form out of
the database to send)
Though this still pulls the full report, are we missing something? Should
the "WhereCondition" be more specific if there are multiple records? Or is
that statement only targeted to the current open form?
We appreciate your input and if you need more specifics let us know.
Christopher