• Form View Error Handling (2003)

    Author
    Topic
    #417102

    I have a field, Bag Number, where Indexed is set to Yes(No Duplicates). When entering data in table view an error is generated if a duplicate bag number is entered. When entering data in a form no error is generated when a duplicate bag number is entered. Is there a setting that will allow the same error to be generated on the form?

    Viewing 0 reply threads
    Author
    Replies
    • #934928

      When you entered the duplicate bag number on your form did you try to save the record? I don’t see the message until an attempt is made to save the record. Are you asking to see the error message come up after a different action?
      Carla

      • #934972

        The record was saved but no error appeared. I only want the error to appear when the record is saved.

        • #934983

          That is very strange. If there is a unique index on a table, you shouldn’t be able to save a record with a duplicate value for the index, whether directly in the table or in a form based on the table. So you now have two records in the table with the same value in the index? confused

          • #934992

            Even though an error message does not appear, the rule of the index does not allow a new record to be added with the same bag number. So there is only one record.

            • #934995

              First, you wrote “The record was saved but no error appeared”, now “Even though an error message does not appear, the rule of the index does not allow a new record to be added”. Which is it?

            • #934996

              Do you have a SetWarnings False anywhere in your form code or perhaps in a macro? Or do you have error handling like “On Error Resume Next”?

            • #935013

              Unless these two statements are added by default, they should not be anywhere in the form code.

            • #935042

              They aren’t added by default, and they definitely should not be in your code, but it’s the first thing to look for when you don’t see an error message in a form.

          • #935012

            In table view an error message appears and the record is not added. On a form, no error message appears and the record is again not added. The user of this little app needs some notification that the record he is trying to add was not successful because of a duplicate bag number.

            • #935016

              Could you post a stripped down copy of your database? See post 401925 for instructions.

            • #935109

              Here you go.

              Thanks
              Hans

            • #935118

              The problem lies in the code behind the ‘returntomenu’ button. Because this has an On Error GoTo statement, errors while saving the record are suppressed (this is a bug in Access in my opinion). You can get around this by trying to save the record before closing the form (through the macro).

              Private Sub returntomenu_Click()
              On Error GoTo Err_returntomenu_Click

              Dim stDocName As String

              If Me.Dirty Then
              RunCommand acCmdSaveRecord
              End If

              stDocName = “Return to Menu”
              DoCmd.RunMacro stDocName

              Exit_returntomenu_Click:
              Exit Sub

              Err_returntomenu_Click:
              MsgBox Err.Description
              Resume Exit_returntomenu_Click
              End Sub

            • #935211

              Those three lines of code fixed the problem. Many thanks HansV

    Viewing 0 reply threads
    Reply To: Form View Error Handling (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: