Jumat, 07 April 2017

Re: [MS_AccessPros] Inconsistent Error 424 - Object Required

 

Thank you.  That relieves me.  I have seen multiple recommendations that ALL procedures should include error management.  I have many, many small procedures like this that do not contain error management and I was a little concerned over the effort required to add error management to all of them.



---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

David-

Basically, your code in the sample command button is simple:

    If Me.lstEquipment.ItemsSelected.Count > 0 Then
        DoCmd.OpenForm "frmSamplePoint", acNormal, , , acFormAdd, acDialog, _
        lstEquipment.Value
        
        Me.lstSamplePoints.Requery
    Else
        MsgBox "You must select Equipment to which the new Sample Point is to be added." _
        , vbInformation, gstrAppTitle
    End If

Despite the fact that I recommend putting error trap code in *all* procedures, for something as simple as this, I might not bother.  Provided the form exists and you get no compile errors, this code *should* never trip an error.  If it does, then there may be a problem with your Access install or corruption in the database.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On Apr 7, 2017, at 4:09 PM, david.pratt@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



Yes there is code in frmSamplePoint and it has your Form_Error and SaveIt() error management code. Per my post, that form does not appear to be the problem.

I did as you suggested and commented out the error management.  Right now, I cannot get it to error again.  Hopefully it comes back so I can clear this up.

Can you answer my "general" question in the original post about what type of error management should be in these command button procedures which call a form which contains your error management procedures?



---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

David-

I don't see anything in that code that should cause a problem.  Is there code in frmSamplePoint?  Does it also have error traps?

You could try temporarily commenting out the On Error statement (just put a ' at the beginning of the line).  If the error occurs again, the default error handler will give you a chance to click Debug to jump into the code to see which line is throwing the error.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On Apr 7, 2017, at 3:11 PM, david.pratt@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



I have an unbound form with three cascading list boxes and each list box has an Add and a Delete command button.  The Add button on the third list box is inconsistently throwing an error 424 Object Required.  I put in a break and so far when I step through I have been unable to get it to error. 

I added John's error management and error logging and verified that the form that is called for the record addition is not the cause of the error.  The error is being logged as an error from the ADD command button on the unbound form.  The error apparently occurs after the form is closed and processing returns to the code in the  AddNew list button click event.  This is verified by the fact that the new record is created in spite of throwing the error. The only step performed after closing the new record form is a requery of the list box.  

My code is below if anyone can possibly see what I am doing incorrectly.

I also have a general question about error management in this scenario where I have a command button calling a form.  I now have John's Form_Error and SaveIt() function error management on all of my ADD forms.  What kind of error management should I have on the command button procedures which call the forms?  Obviously Error 424 is possible.  However, I don't want to code in management of a bunch of errors which cannot happen in this scenario.  Right now most all of these procedures merely have:
   MsgBox err.description
   Resume Done
Based on this experience, this certainly is not adequate.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Private Sub cmdNewSamplePoint_Click()
    Dim lngErr As Long, strErr As String
    On Error GoTo ErrHandler
    
    If Me.lstEquipment.ItemsSelected.Count > 0 Then
        DoCmd.OpenForm "frmSamplePoint", acNormal, , , acFormAdd, acDialog, _
        lstEquipment.Value
        
        Me.lstSamplePoints.Requery
    Else
        MsgBox "You must select Equipment to which the new Sample Point is to be added." _
        , vbInformation, gstrAppTitle
    End If
Done:
    Exit Sub
ErrHandler:
    Select Case Err 'identify the error
        Case errCancel, errCancel2, errPropNotFound ' Cancel - ignore; Variables are declared in modGlobals
            Resume Done
        Case errDuplicate  ' Duplicate row - custom error message
            MsgBox "This record already exists.  Enter a new record or click Cancel.", vbCritical + vbRetryCancel, gstrAppTitle
            'Me.txtSomeControlName.SetFocus
        Case errInvalid, errValidation, errInputMask, errGeneral, errTableValidate
            ' Validation rule - custom error and log
            MsgBox "You have failed to enter a required value or have entered an invalid value. ", _
                vbCritical + vbRetryCancel, gstrAppTitle
            ErrorLog Me.Name & "_Save", Err, Error
        Case Else
            ' Undefined error - log to table ErrTable and let error display; ErrorLog is a Public Sub in modUtility
            ' Save the error code values because ErrorLog may get additional errors
            lngErr = Err
            strErr = Error
            ErrorLog Me.Name & "_cmdNewSamplePoint", lngErr, strErr
            MsgBox "Error attempting new Sample Point: " & lngErr & " " & strErr & Chr$(13) & Chr$(10) & "Try again or click Cancel to close without saving.", vbRetryCancel, gstrAppTitle
    End Select
    Resume Done
End Sub

 







__._,_.___

Posted by: david.pratt@outlook.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar