Results 1 to 5 of 5
  1. #1
    brownpride is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    10

    Using 1 Command Button to Export 2 forms Simultaneously

    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

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You do know that you can create a procedure that invokes each button, right?

  3. #3
    brownpride is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    10
    Quote Originally Posted by RuralGuy View Post
    You do know that you can create a procedure that invokes each button, right?
    If I do that, it doesn't apply the filter to frmSell. It just exports all the records and attaches it to an email.

    If I click the button on frmSell, it only exports 1 record, so the code is right, I just can't get it to happen all at once from frmBuy.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So you do not know how to open the Recordset of the frmSell and apply the where clause you need?

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    I would solve this by having the form on-click button procedure call a sub in a module, with the on-click event using tempvars to store all the variable data fields. Then the code in the module refers to the tempvars to set up the email.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. command button to export to excel
    By jains in forum Forms
    Replies: 5
    Last Post: 06-30-2015, 06:27 PM
  2. Replies: 2
    Last Post: 01-29-2013, 07:01 PM
  3. Replies: 0
    Last Post: 03-24-2011, 11:09 PM
  4. Replies: 0
    Last Post: 03-24-2011, 09:59 AM
  5. Export Command Button in Form
    By jjmartinson in forum Forms
    Replies: 3
    Last Post: 08-25-2009, 01:28 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums