I'd like to be able to create a custom error. Can someone help? Thanks, Jeremy
Printable View
I'd like to be able to create a custom error. Can someone help? Thanks, Jeremy
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
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
Works for me. Thanks, Jeremy