?
Solved

Validating entry on form closure

Posted on 1998-08-31
5
Medium Priority
?
259 Views
Last Modified: 2012-06-27
I use the BeforeUpdate event on a form to validate data entry and cancel the event if the data is missing. This works fine when the user tries to move off the record.
My problem is if a user tries to close the form. The BeforeUpdate event traps the error however the close action still continues and the user is advised that "You can't save this object at this time .... Do you want to close?" YES/NO.

I would like to be able to get rid of this message and prevent the user from closing until the correct data is added or the user selects to undo the record then close

is this possible?
0
Comment
Question by:mutrus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Author Comment

by:mutrus
ID: 1960757
Edited text of question
0
 
LVL 10

Expert Comment

by:brewdog
ID: 1960758
What I've done is take a suggestion from a developer's handbook and refuse to let the user close the form without going through one of my buttons.

I just set up a boolean (or integer, depending on your Access version) variable like "fClose", then make it false on Form_Load. When the user clicks one of my close buttons, I make fClose true; on the Form_Unload event, I check the value of fClose -- if it's true, fine; if it's false, I cancel the unload.

brewdog
0
 
LVL 6

Expert Comment

by:devtha
ID: 1960759
What you can do is to check for each control for valid values in the ONClose event.
Basically take all before update code for each control and paste them in close event. This way you can have if statement for each control.
if text1 <> "Hello" then
msgbox "please put bla bla in text1"
docmd.cancelevent
exit sub
end if

Something like this. I am putting this here from the top of my head so please check the syntax.

0
 

Author Comment

by:mutrus
ID: 1960760
For Devtha
your answer will work only if I have a close button on the form. I use the inbuilt toolbar close button which first carries out the Before Update Event (but doesn't cancel the event), then goes on and displays the original error message (see my original question) then runs the On close Event (also doesn't cancel the event)then closes the form.

For Brewdog
I like your approach however need for infomation. I can't quite get it to work. Also how can this method be applied to stopping the form being close when the user clicks either the close window X or the close application X on the title bar(s)

Thanks
0
 
LVL 1

Accepted Solution

by:
ljb earned 100 total points
ID: 1960761
You can only cancel the unload event, not the close, so if you put devtha's code into there it will work.  You could call your before update code from there and because you can cancel the event, it will cancel if you have a docmd.cancel event in your before update event code.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question