|
-
Oct 30th, 2002, 03:30 PM
#1
Thread Starter
Fanatic Member
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.
-
Oct 30th, 2002, 03:36 PM
#2
Frenzied Member
Read about Err Object in MSDN
VB Code:
Dim Msg
' If an error occurs, construct an error message
On Error Resume Next ' Defer error handling.
Err.Clear
Err.Raise 6 ' Generate an "Overflow" error.
' Check for error, then show message.
If Err.Number <> 0 Then
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.Helpfile, Err.HelpContext
End If
-
Oct 30th, 2002, 03:42 PM
#3
Frenzied Member
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:
Public Function pwdConnect()
Dim strMsg As String
Dim strTitle As String
Dim strStyle As String
Dim strResponse As String
On Error GoTo Mover
Set dbLogin = OpenDatabase("d:\net doctor\db2.mdb")
Set rstLogin = dbLogin.OpenRecordset("Access", adOpenDynamic)
With rstLogin
.OpenRecordset
If (IsNull(rstLogin.Fields(0))) = True Or (rstLogin.Fields(1)) = True Then
strStyle = vbYesNo + vbQuestion
strMsg = "No User account Exists, Would you like to create one now?"
strTitle = "NET DOCTOR"
strResponse = MsgBox(strMsg, strStyle, strTitle)
If strResponse = vbYes Then
Load frmCreate
Me.Hide
frmCreate.Show
ElseIf strResponse = vbNo Then
Me.Show
ElseIf (IsNull(rstLogin.Fields(0))) = False Or (rstLogin.Fields(1)) = False Then
Me.Show
End If
End If
End With
Exit Function
Mover:
MsgBox "There is Current no record"
If rstLogin.EOF = True Then
rstLogin.AddNew
Resume
End If
End Function
-
Oct 30th, 2002, 04:12 PM
#4
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|