Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Posts
    7

    Question Unanswered: Cancel a Report called through more than one form

    I tried looking for previous solutions to a similar problem, but could not loacte any, so here goes:

    I have a form from which I can open all my reports. Included in this form is a list of all repoorts.
    One of my reports calls a parameter form when it opens asking the user for the criteria they wish to use to run the report.
    On this parameter form, I have included a cancel button so that the user can cancel this report. However, because the action that prompts this reports to run is already initiated, I am having a hard time getting this cancel button to function properly.

    The code I have thus far is below:

    frmReportSelector:

    Private Sub ProcessReport(intAction As Integer)

    If Not IsNull(lstReports) Then
    DoCmd.OpenReport lstReports, intAction
    End If

    End Sub
    (lstReports is the List Box displaying report names)
    ----------------------------------------------------------------------
    Private Sub cmdPreview_Click()

    ProcessReport acViewPreview

    End Sub
    ----------------------------------------------------------------------

    Report_Monthly_Consolidations

    Private Sub Report_open(Cancel As Integer)

    [Forms]![frmReportSelector].Visible = False
    DoCmd.OpenForm "frmSelectMonth", acNormal, "", "", , acDialog

    End Sub
    ----------------------------------------------------------------------

    frmSelectMonth

    Private Sub Form_Open(Cancel As Integer)

    [Reports]![Monthly Consolidations].Visible = False

    End Sub
    ----------------------------------------------------------------------

    Private Sub cmdOK_Click()

    [Reports]![Monthly Consolidations].Visible = True
    [Forms]![frmSelectMonth].Visible = False

    End Sub
    ----------------------------------------------------------------------

    Private Sub cmdCancel_Click()

    DoCmd.CancelEvent

    'DoCmd.Close acReport, "Monthly Consolidations"
    DoCmd.Close acForm, "frmSelectMonth"
    DoCmd.OpenForm "frmReportSelector", acNormal, "", "", , acNormal

    End Sub
    ----------------------------------------------------------------------

    It is the final procedure that is giving me trouble; if I uncomment the Docmd.Close acReport... statement, I get a runtime error stating that the action cannot be carried out while the report is being processed ('Run Time Error 2585:')
    Is there anyway I can get this cancel button to function, or do I just need to do away with it altogether given the sequence of events that occurs?

    Any ideas out there?

    Thanks alot,

    Tom

  2. #2
    Join Date
    Apr 2002
    Location
    Illinois
    Posts
    133
    Twilczak,

    One option to consider is to not initiate the report until the parameters have been chosen. I'm not sure you can do this and still use your list box. Another option is to use error trapping. I am not real familiar with using the "OnError" porerty but I have seen it in code I have copied. These aren't real specific answers but I hope they can lead you to a solution.

    Good Luck!
    SteveH

  3. #3
    Join Date
    Jan 2002
    Location
    UK
    Posts
    67
    You may use a global variable to retrun the value from the Form to the Report and then use the following code in the Open event of the Report:


    Report_Monthly_Consolidations

    Private Sub Report_open(Cancel As Integer)
    [Forms]![frmReportSelector].Visible = False
    DoCmd.OpenForm "frmSelectMonth", acNormal, "", "", , acDialog

    if g_cancelButton = 99999 then
    cancel = true
    DoCmd.Close acForm, "frmSelectMonth"
    DoCmd.OpenForm "frmReportSelector", acNormal, "", "", , acNormal
    end if

    end sub


    rem in the form at cancel button, put this code
    Private Sub cmdCancel_Click()

    rem docmd.CancelEvent
    g_cancelButton = 99999

    End Sub


    I have not tried this code, but it should work, The same type of wortk is being done in one of my databases.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •