locked
Closing report on Deactivate RRS feed

  • Question

  • Is there some code I can enter to close the form on deactivate, as it freezes when closing? and I cant send email

    Report name is [rptGenericReportEmail]

    Thanks For any Help................bob 

    Private Sub Report_Deactivate()
    On Error GoTo Error_Handler

    Dim stDocName As String
    Dim strFormat     As String

       Select Case Me.tbEmailOption.value

          Case "ADOBE"
             strFormat = acFormatPDF
          Case "WORD"
             strFormat = acFormatRTF
          Case "SNAPSHOT"
             strFormat = acFormatSNP
              Case "TEXT"
             strFormat = acFormatTXT
              Case "HTML"
             strFormat = acFormatHTML
          Case Else
             strFormat = acFormatHTML
       End Select

     Select Case Me.OpenArgs
     Case "OwnerPaymentMethod"
     
    stDocName = "rptGenericReportEmail"
    DoCmd.SendObject acReport, stDocName, strFormat, , , , "Client Payments", "These are Clients Monthly Payments", , True

     Case "PaymentMethod"
     
     stDocName = "rptGenericReportEmail"
    DoCmd.SendObject acReport, stDocName, strFormat, , , , "Monthly Invoices", "These are Monthly Invoice Totals", , True


    Case "MonthlyPaid"
     
     stDocName = "rptGenericReportEmail"
    DoCmd.SendObject acReport, stDocName, strFormat, , , , "Monthly Invoice Totals", "These are Monthly Invoice Totals", , True
    End Select

    Error_Handler:
        Select Case Err.Number
        Case 2501
            Exit Sub
        Case 2487
                Resume Next
        Case Else
          
        End Select


    End Sub


    xxx

    Friday, April 7, 2017 11:49 PM

All replies

  • For one thing, your TRUE input argument is in the wrong place.

    DoCmd.SendObject acReport, stDocName, strFormat, , , , "Client Payments", "These are Clients Monthly Payments", , True

    Should be

    DoCmd.SendObject acReport, stDocName, strFormat, , , , "Client Payments", "These are Clients Monthly Payments", True

    and I'm not sure about using the Deactivate event, I'd be more inclined to use the Close event, or even better my own close button click event.


    Daniel Pineault, 2010-2016 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Saturday, April 8, 2017 12:41 AM
  • Hi TurnipOrange,

    you had mentioned that,"Is there some code I can enter to close the form on deactivate, as it freezes when closing? and I cant send email".

    I can see that you used the above mentioned code for sending the reports in mail.

    from your description it looks like you want to find when report/ form is inactive for some amount of time then you want to call code above and close the form / report.

    you can try to refer code below to find inactivity.

    Sub Form_Timer()
       ' IDLEMINUTES determines how much idle time to wait for before
       ' running the IdleTimeDetected subroutine.
       Const IDLEMINUTES = 1
    
       Static PrevControlName As String
       Static PrevFormName As String
       Static ExpiredTime
    
       Dim ActiveFormName As String
       Dim ActiveControlName As String
       Dim ExpiredMinutes
    
       On Error Resume Next
    
       ' Get the active form and control name.
    
       ActiveFormName = Screen.ActiveForm.Name
       If Err Then
          ActiveFormName = "No Active Form"
          Err = 0
       End If
    
       ActiveControlName = Screen.ActiveControl.Name
          If Err Then
          ActiveControlName = "No Active Control"
          Err = 0
       End If
    
       ' Record the current active names and reset ExpiredTime if:
       '    1. They have not been recorded yet (code is running
       '       for the first time).
       '    2. The previous names are different than the current ones
       '       (the user has done something different during the timer
       '        interval).
       If (PrevControlName = "") Or (PrevFormName = "") _
         Or (ActiveFormName <> PrevFormName) _
         Or (ActiveControlName <> PrevControlName) Then
          PrevControlName = ActiveControlName
          PrevFormName = ActiveFormName
          ExpiredTime = 0
       Else
          ' ...otherwise the user was idle during the time interval, so
          ' increment the total expired time.
          ExpiredTime = ExpiredTime + Me.TimerInterval
       End If
    
       ' Does the total expired time exceed the IDLEMINUTES?
       ExpiredMinutes = (ExpiredTime / 1000) / 60
       If ExpiredMinutes >= IDLEMINUTES Then
          ' ...if so, then reset the expired time to zero...
          ExpiredTime = 0
          ' ...and call the IdleTimeDetected subroutine.
          IdleTimeDetected ExpiredMinutes
       End If
    End Sub
    
    


    Sub IdleTimeDetected (ExpiredMinutes)
       Dim Msg As String
       Msg = "No user activity detected in the last "
       Msg = Msg & ExpiredMinutes & " minute(s)!"
       MsgBox Msg, 48
    End Sub
    
    

    Reference:

    How to detect User Idle Time or Inactivity in Access

    you can try to modify the code as per your requirement and try to implement it in your database.

    if I misunderstand something in your above mentioned description then please correct me.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 10, 2017 5:11 AM
  • Hey TurnipOrange,

    As Daniel points out, I would avoid Deactivate event as well.

    Tuesday, April 11, 2017 1:58 AM