Results 1 to 13 of 13
  1. #1
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    72

    Close - Ignore validation

    Hello, I have a problem in that I have a close button on a form - this loads an embedded macro that simply closes the windows (set warnings is set to "no").If the form is blank and the user clicks close, it works brilliantly. If the user has half filled in the form, it then says the x, y and z fields can't be empty, cannot save the record at this time etc. How do I set it so if the user clicks close, any input is ignored and the form is closed?Thank you!

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    One way is to have a CheckComplete procedure which runs in the close button code

    The idea is that it would check a list of controls that need to be filled before the form can be closed.
    I prefer to then pop up a message listing unfilled controls and changing their background colour.
    However if preferred, you could use it to empty any filled controls in a partly completed record then close the form

    Suggest you use vba procedure rather than an embedded macro
    Last edited by isladogs; 04-27-2018 at 03:33 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    72
    Thank you. Is there a simple way in vba then of just closing the form and ignoring all the values?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    How do I set it so if the user clicks close, any input is ignored and the form is closed?
    IMHO, this is the incorrect approach. There is a basic standard that's all about how Windows apps should be laid out and behave, and this approach doesn't fit. Mind you, I'm sure I'm guilty of not adhering to that standard 100% as it is quite involved. Anyway, my answer would be don't do what you are doing as Close has one meaning, and Cancel has another. In the simplest terms, your form should have a Save/Close button and a Cancel button and not be too close together. Should be fairly obvious as to what they do. You choose to permit the cancellation of the Cancel if a form is partially filled out or not by way of design. I would hate to lose a lot of work if I clicked the wrong one. Point is that you have to make the decision as to whether or not that's warranted or just a pesky prompt. Another choice is Save, Close, Cancel, and a prompt to force a conscious decision to not save before closing. However, the Save without closing is more complex, but it does allow you to save a partial record and pause (or leave and come back) as long as the minimum required fields are filled in.
    Last edited by Micron; 04-26-2018 at 01:15 PM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    72
    I understand what you're saying. Thank you for the tips.

  6. #6
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    72
    Is there any VBA script for clearing a form or would I need to specify each control value individually?

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974

    Post

    I also think this isn't the way to proceed and suggested a better alternative in my first reply.

    If you really want to do this, you either need to list all controls individually or loop through each in turn to set to a ZLS
    Something like this should work but test it out in a non critical situation first!

    Code:
    Dim ctrl As Access.Control
    
    For Each ctrl In Screen.ActiveForm.Controls
          If ctrl.ControlType = acTextBox Then ctrl = ""
    Next ctrl
    Note its been limited to textboxes so label captions aren't cleared
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    72
    Thank you - I know not ideal but I'm no expert - unfortunately not even a novice so this worked for me:
    Code:
    Private Sub close_form_Click()On Error Resume NextDim ctl As ControlFor Each ctl In Me.Controls    If ctl.ControlType = acTextBox Then ctl = NullNextSet ctl = NothingDoCmd.CloseEnd Sub

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    It's more convoluted than it needs to be.
    The code I gave is more efficient though you can use Null rather than "" if you prefer
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Wouldn't Me.Undo be simpler?

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Quote Originally Posted by Micron View Post
    Wouldn't Me.Undo be simpler?
    Definitely yes but only if all the controls are bound
    The other method works for both bound & unbound
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    If any were not bound, the warning about saving a record wouldn't apply to them so I don't see how that's relevant. Unbound controls don't cause warnings about records, do they? Close a form full of unbound controls and nothing happens. No partial record (because they're not bound). No prompts or warnings. Reopen form and it's blank.

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    True but I just went for a method that cleared both types of control.
    I'm not saying its a better approach & I wouldn't dream of mentioning nit-picking either!

    Me.Undo is almost certainly absolutely perfect for the OP's needs. I commend that approach to the OP

    We both agree that this isn't the best way to proceed when closing a partially completed form
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 12-05-2017, 03:31 PM
  2. Replies: 21
    Last Post: 09-16-2016, 08:44 PM
  3. Replies: 2
    Last Post: 06-16-2015, 03:52 AM
  4. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  5. Replies: 2
    Last Post: 06-20-2011, 03:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums