Results 1 to 4 of 4

Thread: Custom Errors [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    Arrow Custom Errors [RESOLVED]

    I'd like to be able to create a custom error. Can someone help? Thanks, Jeremy
    Last edited by JCScoobyRS; Oct 30th, 2002 at 04:13 PM.
    He who listens well, speaks well.

  2. #2
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Read about Err Object in MSDN
    VB Code:
    1. Dim Msg
    2. ' If an error occurs, construct an error message
    3. On Error Resume Next   ' Defer error handling.
    4. Err.Clear
    5. Err.Raise 6   ' Generate an "Overflow" error.
    6. ' Check for error, then show message.
    7. If Err.Number <> 0 Then
    8.    Msg = "Error # " & Str(Err.Number) & " was generated by " _
    9.          & Err.Source & Chr(13) & Err.Description
    10.    MsgBox Msg, , "Error", Err.Helpfile, Err.HelpContext
    11. End If
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  3. #3
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    In the following code, the program looks if a user accoun exists or not, if it does not it asks user to create it and if any error occurs, the Error Handler, raises a Custom Error...is this is what you are after

    VB Code:
    1. Public Function pwdConnect()
    2.     Dim strMsg As String
    3.     Dim strTitle As String
    4.     Dim strStyle As String
    5.     Dim strResponse As String
    6.     On Error GoTo Mover
    7.     Set dbLogin = OpenDatabase("d:\net doctor\db2.mdb")
    8.     Set rstLogin = dbLogin.OpenRecordset("Access", adOpenDynamic)
    9.     With rstLogin
    10.     .OpenRecordset
    11.     If (IsNull(rstLogin.Fields(0))) = True Or (rstLogin.Fields(1)) = True Then
    12.         strStyle = vbYesNo + vbQuestion
    13.        strMsg = "No User account Exists, Would you like to create one now?"
    14.        strTitle = "NET DOCTOR"
    15.        strResponse = MsgBox(strMsg, strStyle, strTitle)
    16.     If strResponse = vbYes Then
    17.         Load frmCreate
    18.         Me.Hide
    19.         frmCreate.Show
    20.     ElseIf strResponse = vbNo Then
    21.         Me.Show
    22.     ElseIf (IsNull(rstLogin.Fields(0))) = False Or (rstLogin.Fields(1)) = False Then
    23.         Me.Show
    24.     End If
    25.     End If
    26.    
    27.     End With
    28.     Exit Function
    29. Mover:
    30.         MsgBox "There is Current no record"
    31.         If rstLogin.EOF = True Then
    32.             rstLogin.AddNew
    33.             Resume
    34.         End If
    35. End Function
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  4. #4

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    Thanks

    Works for me. Thanks, Jeremy
    He who listens well, speaks well.

Posting Permissions

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



Click Here to Expand Forum to Full Width