Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2003
    Posts
    6

    Unanswered: Report dissapears after opening

    I want to open a report each time with a different recordsource which is a query of my database that the user selects.
    So, I use the code shown in the Report_Open event procedure

    Private Sub Report_Open(Cancel As Integer)

    Me.RecordSource = strQueryName

    End Sub

    strQueryName is the name of the query the user selected and is a public variable.
    What happens is that the report seems to open and dissapear immediately.
    When I debug the code using the 'Step Into' command in the VBA IDE everything works fine!

    Can anyone suggest a solution?
    Thank you in advance.

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    How are you opening the report? Normal? Preview?

  3. #3
    Join Date
    Dec 2003
    Posts
    6
    Originally posted by M Owen
    How are you opening the report? Normal? Preview?
    I open it with the Preview view (acViewPreview)

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Well the only thing I can think of is if the queryname is invalid or generates a result that has no records ... Can you post an example of what strQueryName contains?

    Are you providing the user with a list of queries? Or are you constructing a query on the fly?

  5. #5
    Join Date
    Dec 2003
    Posts
    6
    Originally posted by M Owen
    Well the only thing I can think of is if the queryname is invalid or generates a result that has no records ... Can you post an example of what strQueryName contains?

    Are you providing the user with a list of queries? Or are you constructing a query on the fly?
    The user selects from a list of four queries from a combo box on a form. The contents of the combo box are stored in strQueryName. So, strQueryName contains the name of an already existing query. Then, I open the report in Preview view from within the form.

    The thing is that when debugging, every variable and instance have valid values that appear in the locals and watches window. When running the code with no breakpoints the problem occurs with no error messages.

    This is exactly what I get from the watches window for strQueyName

    Watch : : strQueryName : "Update_Mailing_List" : Variant/String :

    Update_Mailing_List is one of the queries that is in the combobox list

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Ok ... Does the report you're running support each of the queries that can be selected?


    Ah ... Just thought of something ... What kind of queries are you running??? I just saw the name of "Update_Mailing_List" ...

  7. #7
    Join Date
    Dec 2003
    Posts
    6
    Originally posted by M Owen
    Ok ... Does the report you're running support each of the queries that can be selected?


    Ah ... Just thought of something ... What kind of queries are you running??? I just saw the name of "Update_Mailing_List" ...
    Yes, the report supports them. When I change the recordsource manually the report works perfect. The queries are all select queries and they retrieve values from one table.
    To be more specific, I have a table with customers and i've created these queries that contain the same fields (and more, but are not used in the report) such as company, name, address, zip code etc. but with different criteria.

  8. #8
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Make a suggestion: Pop a MsgBox in the Report's Open method displaying the strQueryName's contents. Verify that a query name is in it. I use somewhat the same tacttic for my reports ... Ex:

    Code:
    Private Sub Report_Open(Cancel As Integer)
        Dim IsOK As Integer
    
        MyUserID = CurrentUser()
    
        DBConnectionActive = False
        
        IsOK = EstablishDBConnection
        If IsOK = 0 Then
            Cancel = 1
            Exit Sub
        End If
        DBConnectionActive = True
    
        Dim ParmListString() As String
        ' Format:
        '
        ' Labor & Material Detail Report table, W.O. #
        '
        ParmListString = Split(Forms![WO Billing Preview].ParameterTxt, ",", -1, vbTextCompare)
    '    ParmListString = Split(Me.OpenArgs, ",", -1, vbTextCompare)
        RptTbl = ParmListString(0) & ""
        WONumber = ParmListString(1) & ""
        
        RetrieveWOAttributes
        
        Me.RecordSource = RptTbl
    End Sub

  9. #9
    Join Date
    Dec 2003
    Posts
    6
    I 've already done this and the correct query name is displayed. I am sure that there is nothing wrong with the strQueryName. I don't know what else to check...

  10. #10
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    If you run the query directly you get a result set?

  11. #11
    Join Date
    Dec 2003
    Posts
    6
    Originally posted by M Owen
    If you run the query directly you get a result set?
    Yes.
    Everything works perfect except when the code is running.

  12. #12
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    Have you checked if you are not running the report in hidden mode ??


    Originally posted by sharq_2134
    Yes.
    Everything works perfect except when the code is running.

  13. #13
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    I had once the same problem!
    After some time I figured out what was wrong : I opened the report from a from that had its property Modal set to True.
    So every time I opened the report, it did open but I could not see it because the form kept the focus.
    When debugging this problem, all went well because the form wasn't loaded at that time.

    My hint : check the form where you open the report!

Posting Permissions

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