Results 1 to 3 of 3
  1. #1
    Johnny Chow is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    4

    Can't open report

    I made a open report button on the form, it work good. But, after I wrote code on the report open, there is a message box said:"this form or report does not exist." please help


    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click




    Dim stDocName As String


    stDocName = "Disbursements Sum Query"
    DoCmd.OpenReport stDocName, acPreview


    Exit_Command13_Click:
    Exit Sub


    Err_Command13_Click:
    MsgBox Err.Description
    Resume Exit_Command13_Click

    End Sub



    Private Sub Report_Open(Cancel As Integer)

    sql = "select [Catagoey],[Disbursements],[Sum Of Total]from [Disbursements Sum Query]Where[Disbursements Sum Query].[Date By Year]=" & [Form_Disbursements Sum Query].[Combo7].Value

    Debug.Print sql

    Me.RecordSource = sql

    Set rst = Nothing

    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Welcome to the forum....

    It appears that you have 3 object types with the same name:
    A query with the name "Disbursements Sum Query",
    A form with the name "Disbursements Sum Query" and
    A report with the name "Disbursements Sum Query"

    It has been a while since I looked into this, but IIRC, this is possible because internally, Access adds a prefix to each object type.
    A query would be named "Query_Disbursements Sum Query", a form would be named "Form_Disbursements Sum Query" and a report would be named "Report_Disbursements Sum Query".
    BUT you should never use these names for anything! Again, these are ACCESS INTERNAL names.

    It would be much better to use prefixes like "qryDisbursementsSumQuery", "frmDisbursementsSumQuery" and "rptDisbursementsSumQuery"
    (Notice I removed the spaces. You should never use spaces in object names.)


    There is a much easier method to limit the records in a report.




    The report record source should be
    Code:
    "SELECT [Catagoey],[Disbursements],[Sum Of Total] FROM [Disbursements Sum Query]
    This will return all records. To limit the records, use the WhereCondition parameter of the DoCmd.OpenReport Method


    The DoCmd syntax is
    Code:
    DoCmd.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)
    So the VBA code would look like:
    Code:
    Private Sub Command13_Click()
       On Error GoTo Err_Command13_Click
    
       Dim stDocName As String
    
       stDocName = "Disbursements Sum Query"   '<<-- if this is a report, why is "query" in the report name??
       DoCmd.OpenReport stDocName, acPreview,, "[Date By Year]=" & Me.[Combo7]
     
    Exit_Command13_Click:
       Exit Sub
    
    Err_Command13_Click:
       MsgBox Err.Description
       Resume Exit_Command13_Click
    
    End Sub
    There would not be code in the report open event.



    Good luck with your project....

  3. #3
    Johnny Chow is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    4
    it work good, Thank you very much

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

Similar Threads

  1. Replies: 5
    Last Post: 02-28-2017, 02:45 PM
  2. Replies: 2
    Last Post: 03-13-2016, 02:01 PM
  3. Replies: 4
    Last Post: 12-09-2015, 09:02 AM
  4. Replies: 3
    Last Post: 07-22-2014, 11:37 AM
  5. Help on report to open form to open query...
    By saseymour in forum Programming
    Replies: 13
    Last Post: 07-16-2013, 08:11 AM

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