Results 1 to 3 of 3
  1. #1
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71

    On Error handling

    Hi,



    I have a line of code that throws runtime error 3075 when the records run out. I'm ok with that because it works for all records that actually exist. However, I need to use On Error handling for the line in italics and just throw a message box. The code I have does that, but for every single run of the code- not just just on runtime 3075. I'm pretty new to the On Error statement. Anybody have an idea of what I've done wrong?

    Code:
     
    Private Function DetectCurrentPlatform() As String
        'change form according to platform
        Dim Platform As String
        On Error GoTo ErrMsg
        Platform = Nz(DLookup("[RequestType]", "tblOrder", "[PPID] = " & getCurrentPPID & " AND [ID] = " & Me.ID), 0)
        ...
    ErrMsg:
        Dim msg As String
        msg = "There are no more records under this PPID."
        MsgBox msg, , "Record Navigation"
    End Function

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Try this:
    Code:
        'change form according to platform
        Dim Platform As String
        On Error GoTo ErrMsg
        Platform = Nz(DLookup("[RequestType]", "tblOrder", "[PPID] = " & getCurrentPPID & " AND [ID] = " & Me.ID), 0)
        ...
    ErrMsg:
      If Err.Number = 3075 then
        Dim msg As String
        msg = "There are no more records under this PPID."
        MsgBox msg, , "Record Navigation"
      Else
        MsgBox "Error Num " & Err.Number & ": " & Err.Description
      EndIf
    End Function
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71
    That fixed it. Thank you!

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

Similar Threads

  1. VBA Error Handling Clear
    By josephff in forum Programming
    Replies: 19
    Last Post: 08-30-2011, 12:12 PM
  2. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  3. Error Handling
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 09-14-2010, 12:17 PM
  4. Error Handling
    By trb5016 in forum Access
    Replies: 2
    Last Post: 08-10-2010, 08:37 AM
  5. #error handling
    By mws5872 in forum Access
    Replies: 4
    Last Post: 05-12-2010, 07:06 AM

Tags for this Thread

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