• Invalid data on form close (2000/sp3)

    Author
    Topic
    #417955

    I’ve got a form of two fields… for one of those fields, “allowzerolength” is set to “no” …

    Here’s the situation: Open up the form with valid data already in it… select the field with the len()>1 restriction. Hit “DEL” to clear out the data in the field. This is fine, since we’re still in the control’s focus… Ahhh, but now — click the form close (“X”) button. POOF!

    I can’t seem to find any code that can correctly capture this event and cancel the form’s close() routine (OR undo changes to the record before closing) without Access popping up some crazy error about how it can’t save the record but do I want to close the form anyway. I’d much rather capture this completely and handle it without popping up error messages.

    But how?

    thanks!
    ..dane

    Viewing 1 reply thread
    Author
    Replies
    • #939182

      Try the Unload event of the form, which has a cancel argument.

    • #939183

      Force the user to close the form through a command button, say cmdClose.

      Private blnCanClose As Boolean

      Private Sub Form_Unload(Cancel As Integer)
      Cancel = Not blnCanClose
      End Sub

      Private Sub cmdClose_Click()
      blnCanClose = (Len(Me.strSomething) > 1)
      If blnCanClose Then
      DoCmd.Close
      End If
      End Sub

      • #939288

        Thanks to both of you for suggestions — however, it seems that even setting Cancel=true on the Unload() event does not actually prevent the form from closing if the table has a required value and does not allow zero-length strings.

        I just removed the required setting from the table, and perform my own checks in the form unload() event…. Not ideal, but acceptable.

        ..dane

    Viewing 1 reply thread
    Reply To: Invalid data on form close (2000/sp3)

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

    Your information: