Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy when report has no data gives run-time error 3270

    In a form I have several fileds to fill in so it can make a sql squery (WHERE AND OR)
    But when the report has no data I'll get the run-time error 3270 (property not found).
    When I debug, it gives this line as problem:
    PHP Code:
    DoCmd.OpenReport "rptlijstcomp"acViewReport 
    In my report I also have
    PHP Code:
    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "There are no records to report"vbExclamation"No Records"
    Cancel True
    End Sub 
    Does someone know how to make the report close when there is no data?

    Many thanks in advance
    greetings Nancy

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    There are two parts needed in the VBA (NB it is VBA not PHP code)
    The first part you have correctly, in the On No Data Event.
    The second part is to add an error handler to the code that opens the report.

    Code:
    Private Sub cmdOpenReport_Click()
    On Error GoTo Err_cmdOpenReport_Click
     
    DoCmd.OpenReport "rptlijstcomp", acViewReport  
    
    Exit_cmdOpenReport_Click:
        Exit Sub
    
    Err_cmdOpenReport_Click:
    If Err.Number = 2501 Then
         Resume Exit_cmdOpenReport_Click
    Else
        MsgBox Err.Description
        Resume Exit_cmdOpenReport_Click
    End If
    End Sub
    The usual error code in this situation is 2501, and that is the one I have handled.
    You are getting 3270. I don't know why. You could try just handling that error as above.
    Regards
    John



  3. #3
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,
    When I add your code, I get an error now "property not found"
    PHP Code:
    On Error GoTo Err_cmdOpenReport_Click
    DoCmd
    .OpenReport "rptlijstcomp"acViewReport
    Exit_cmdOpenReport_Click
    :
    Exit 
    Sub
    Err_cmdOpenReport_Click
    :
    If 
    Err.Number 2501 Then
        MsgBox 
    "error"
         
    Resume Exit_cmdOpenReport_Click
    Else
        
    MsgBox Err.Description
        Resume Exit_cmdOpenReport_Click
    End 
    If 
    The last msgbox result I'll get is
    MsgBox Err.Description
    If I put it in err.number I'll still get 3270 error.
    When I change the code in to this, it will work:
    On Error GoTo Err_cmdOpenReport_Click
    DoCmd.OpenReport "rptlijstcomp", acViewPreview
    Exit_cmdOpenReport_Click:
    Exit Sub

    Err_cmdOpenReport_Click:
    If Err.Number = 3270 Then
    MsgBox "Er zijn geen computers met die selectie", vbInformation
    Resume Exit_cmdOpenReport_Click
    Else
    'MsgBox Err.Description
    'MsgBox Err.Number
    MsgBox "Er zijn geen computers met die selectie", vbInformation
    Resume Exit_cmdOpenReport_Click
    End If
    Last edited by plutoken; 2011-02-23 at 03:26.

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    So you have got it working.

    Error 2501 is the standard error generated when you cancel the opening of a report, so it might be worth handling that also. (In case you manage to find out why 3270 is occuring, and it goes away.)

    Code:
    On Error GoTo Err_cmdOpenReport_Click
        DoCmd.OpenReport "rptlijstcomp", acViewPreview
    Exit_cmdOpenReport_Click:
        Exit Sub
        
    Err_cmdOpenReport_Click:
        If Err.Number = 3270 Then
            MsgBox "Er zijn geen computers met die selectie", vbInformation
             Resume Exit_cmdOpenReport_Click
        ElseIf Err.number=2501 then
             Resume Exit_cmdOpenReport_Click
        Else
            'MsgBox Err.Description
            'MsgBox Err.Number
            MsgBox "Er zijn geen computers met die selectie", vbInformation
            Resume Exit_cmdOpenReport_Click
        End If
    Regards
    John



Posting Permissions

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