|
-
Aug 3rd, 2000, 04:35 PM
#1
Thread Starter
Hyperactive Member
Okay, my day was going great until I discovered this
ridiculous problem:
In the Error event of an ADODC, I have a Select Case series
to display more meaningful error messages to the user. The
problem here concerns the errors that occur when
1) the user tries to enter a record that would create a duplicate value in an indexed field, or
2) the user tries to enter a record that is entirely blank
Code:
Private Sub Adodc1_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
On Error Resume Next
Select Case ErrorNumber
Case 16389 'duplicate record
MsgBox "The class '" & txtClass & "' already exists.", vbExclamation
fCancelDisplay = True
Case 3640 'reference to a deleted object
MsgBox LoadResString(114) & _
vbNewLine & LoadResString(115), vbExclamation
fCancelDisplay = True
With Adodc1
.Recordset.CancelUpdate
.Recordset.Requery
.Refresh
End With
'et cetera et cetera
End Select
This works fine to trap the Duplicate Record error IF the
user clicks on one of the Adodc control arrows. The
problem is that I have an AddRecord routine that is invoked
at various times. This routine also has an error handling
Select Case series.
Code:
Private Sub AddRecord()
'add new record
On Error GoTo Error_En_Base
'enable fields
If Adodc1.Recordset.RecordCount = 0 Then
txtClass.Enabled = True
txtClass.BackColor = vbWindowBackground
End If
txtClass.SetFocus
Adodc1.Recordset.Requery
Adodc1.Recordset.AddNew
Exit Sub
Error_En_Base:
Select Case Err.Number
Case 3021 'no active record
Resume Next
Case 3219 'action not permitted
Resume Next
Case -2147467259 'user has not entered all required fields
MsgBox Err.Description, vbExclamation
'et cetera et cetera
End Select
End Sub
I just discovered that with an Adodc control, Err.Number
-2147467259 could mean one or more of at least 3 different
things.
1) that the entry will create duplicates in the index,
2) that the user has not entered a required field, or
3) that it is not possible to enter a blank record.
The above code does not pass control to the
Adodc1_Error routine, and I can't figure out how to make it
do so.
To an average user, the Microsoft Jet error messages are a
bunch of gibberish. How can I either
1) pass control to the Error routine and leave the AddRecord routine, or
2) determine which of the 3 or more situations represented by Err.Number -2147467259 actually caused the error?
Please, if SOMEONE can help, I will be forever grateful!
End Sub
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
|