Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Messages (Access 2000 / Windows 98)

    I have a feeling that the answer to this is going to be so simple that I will kick myself!

    I have a report that prints with the code:-

    Private Sub RptInvestments_Click()
    On Error GoTo Err_RptInvestments_Click

    Dim stDocName As String

    stDocName = "RptPersonalInvestments"
    DoCmd.OpenReport stDocName, acPreview, , "[PersonID] = " & [PersonID]

    Exit_RptInvestments_Click:
    Exit Sub

    Err_RptInvestments_Click:


    End Sub

    It works very well indeed and just prints out the investments for the person shown on the form at that moment.

    If that person has no investments then this code prints the message

    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "There are no investments to print", , "Personal Investment Report"
    Cancel = -1
    End Sub

    All you do then is click OK and that's it - except for the fact that a message now comes up saying "The open report action was cancelled", so you have to click OK again.

    It's not too much of a problen, but it would be nice if I could suppress the second message.

    Can someone tell me how to do it please

    Michael Peak

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Messages (Access 2000 / Windows 98)

    In the error handler routine add the following code :
    <pre>Private Sub RptInvestments_Click()
    On Error GoTo Err_RptInvestments_Click

    Dim stDocName As String

    stDocName = "RptPersonalInvestments"
    DoCmd.OpenReport stDocName, acPreview, , "[PersonID] = " & [PersonID]

    Exit_RptInvestments_Click:
    Exit Sub

    Err_RptInvestments_Click:

    If Err = 2501 Then
    Resume Exit_RptInvestments_Click
    Else
    strMsg = "error no " & Err.Number & ": " & Err.Description
    End If

    End Sub</pre>

    Francois

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Messages (Access 2000 / Windows 98)

    Hi Francois

    Thank you that fixed it.

    As it happens it did not like the line
    StrMsg = "error no " & Err.Number & ": " & Err.Description

    and wanted me to define it

    so I replaced it with MsgBox "error no " & Err.Number & ": " & Err.Description

    And that was fine

    The irony is that in order to try it I first deleted the two lines after

    Err_RptInvestments_Click:

    and ran it before putting your code in and it worked anyway!!

    I do realise that your way is much better as any other errors will be picked up

    Thank you very much for your help.

    Incidently can I find anywhere a list of the error codes like Err = 2501?

    Michael Peak

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Messages (Access 2000 / Windows 98)

    Have a look at <post#=422879>post 422879</post#>
    Francois

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Messages (Access 2000 / Windows 98)

    Hi Francois

    I went to the post and have made the database. In case anyone else would like a copy I have zipped it up. The snag is it's 139K. Will I be thrown out if I upload it?

    Michael

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Messages (Access 2000 / Windows 98)

    Yes it will be rejected but have you delete all the unknowed error numbers ?
    Have you compact it before you zipped it ?
    If still over the 100k, convert it to Access 97.
    Francois

Posting Permissions

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