Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Oct 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Invalid data on form close (2000/sp3)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Invalid data on form close (2000/sp3)

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

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Invalid data on form close (2000/sp3)

    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

  4. #4
    2 Star Lounger
    Join Date
    Oct 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Invalid data on form close (2000/sp3)

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •