Currently I have 2 command buttons, one on each form (frmBuy and frmSell). The code works on each form independently. I wanted to see if I could export both forms using 1 command button with the record depending on the same Deal Id. So where [frmSell].[Deal ID] = [frmBuy].[Deal ID], however that code and variations of it gives me an error when I use it on frmBuy.
If I place the SendSeller code and button on frmBuy, all of frmSell records are exported. I think if I tweak the strWhere= code it will work, but everything I have tried has been unsuccessful. Any help or advice would be appreciated.
VBA code is below for frmBuy/SendBuyer button. The code for frmSell/SendSeller button are the same, just replaced buy/buyer with sell/seller.
Code:
Option Compare DatabaseOption Explicit
Private Sub SendBuyer_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "frmBuy"
strWhere = "[Deal ID]=" & Me.Deal_ID
DoCmd.ApplyFilter , strWhere
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim fileName As String, todayDate As String
'Export report in same folder as db with date stamp
todayDate = Format(Date, "mm.dd.yy")
fileName = "C:\Users\M\D\Confirms" & "\Confirm " & todayDate & " " & [Company Name] & ".pdf"
DoCmd.OutputTo acForm, "frmBuy", acFormatPDF, fileName, False
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(Forms!frmBuy.[Con])
objOutlookRecip.Type = olTo
.Subject = "Subject"
.BodyFormat = olFormatHTML
.HTMLBody = "<p style='font-size:11pt;font-family:Alte Haas Grotesk'>" & "Dear " & Me.[Con]
.Attachments.Add fileName
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
.Display
End With
Set objOutlook = Nothing
DoCmd.ShowAllRecords
End Sub