I am trying to use a button with the vba coding for SendObject Function
to email a specific report based on the value of another field of the
current record.
The form is a continuous form and the values are either of the field
[IACUC/IBC] are "IACUC" or "IBC". If the value is IACUC, I want the
IACUC report to send, if IBC the IBC report to send. The email button
is located on the continous form details with the record specified and
report is filtered based on the registration form ID number.
I have written the SendObject commands into separate funtions and then
written an IIF function into the button click, but it only pulls up the
IBC report no matter what the value of the IACUC/IBC field. It seems
like I am possibly missing hte current record command? Any
suggestions?
All Code is below.
Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click
Dim stDocName As String
IIf CurrentRecord([IACUC/IBC].Value) = "IBC", IBCMail(), IACUCMail()
Exit_cmdEmail_Click:
Exit Sub
Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click
End Sub
Function IBCMail()
Me.Email_Sent_.Value = 1
stDocName = "Form C"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
'Open current report in preview
DoCmd.OpenReport stDocName, acPreview, "", "[Assigned
Number]=[Forms]![Personnel Form2]![registrations
list]![RegistrationForm ID]"
DoCmd.SendObject acReport, stDocName, "SnapshotFormat",
[Forms]![Personnel Form2]![registrations list]![Email1], , , "Current
IBC Form C", "Please find attached FORM C's listing currently approved
personnel"
End Function
Function IACUCMail()
Me.Email_Sent_.Value = 1
stDocName = "Request for IACUC Approval of Change Report"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
'Open current report in preview
DoCmd.OpenReport stDocName, acPreview, "", "[Protocol
Number]=[Forms]![Personnel Form2]![registrations
list]![RegistrationForm ID]"
DoCmd.SendObject acReport, stDocName, "SnapshotFormat",
[Forms]![Personnel Form2]![registrations list]![Email1], , , "Current
IBC Form C", "Please find attached IACUC Protocols Report listing
currently approved personnel"
End Function