Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation - if validation fails when closing form, data is lost 1

Status
Not open for further replies.

dchrinian

Programmer
Jul 31, 2000
2
0
0
US
I have validation in the Before_Update event.&nbsp;&nbsp;Works great except for the unload of a form.&nbsp;&nbsp;<br>Scenario - <br>1) user changes data in a field<br>2) clicks the X on the form to close the form, triggering the unload event<br>3) prior to the unload event, the before_update event occurs<br>4) in this scenario, the user entered invalid data, the before_update event is cancelled (cancel = true) due to the validation<br>5) for some reason, the form_error event occurs - displaying a message box &quot;You can't save this record at this time - do you want to close and lose your data?&quot; (error 2169).&nbsp;&nbsp;If you click Yes, the form closes and all information is undone. If you answer No, the form redisplays with the data in it.&nbsp;&nbsp;This is the path I would like to take without having to deal the MS Access's not so <br>user-friendly at all.&nbsp;&nbsp;I tried to intercept to place my own message by setting the RESPONSE property of the form_error event to acDataErrContinue.&nbsp;&nbsp;The problem is - it takes the path as if you had answered &quot;Yes&quot; to the earlier question.<br><br>I would really like the data to stay on the screen giving the user the chance to correct the problem before exiting the screen.<br><br>Any insite would be greatly appreciated - this is one of those problems you just sit and spin your wheels on!<br>Thanks to anyone in advance!<br><br>Frustrated in New Jersey!<br>
 
Use Error trapping to trap the specific error.&nbsp;&nbsp;Then put a messagebox in the error handling routine to display your message when the error occurs.<br><br>eg<br><br>On Error GoTo Error_Handling<br><br>Error_Handling:<br>&nbsp;&nbsp;&nbsp;If Err = 2169 then<br>&nbsp;&nbsp;&nbsp;Msgbox = &quot;Your Message&quot;<br>
 
Thanks for your quick response.<br><br>I did put an error message in, but in order to do so, you must bypass the MS Access message - which, if used, displays a yes/no question - whether to close and lose the data or remain open with the data on the screen (this is the desired path).<br><br>Unfortunately, when I set the response to acDataErrContinue (to use my own message), I don't seem to have the opportunity to keep the data on the screen.&nbsp;&nbsp;It leaves the form error event, then goes to the unload event, which I cancel, knowing there is an error.&nbsp;&nbsp;But the problem is the screen gets cleared, I lose any data the user has typed in.<br><br>So, the user doesn't know what they did wrong, and I'm back to square one.<br><br>It's frustrating when Access does not give you control when you need it.<br><br>Thanks,<br>Donna
 
Sorry, Donna - I misunderstood.<br><br>Don't use the acDataErrContinue constant.&nbsp;&nbsp;It isn't necessary to display your message, as by trapping the specific error (2169), you automatically circumvent the Access default response.&nbsp;&nbsp;So your error routine needs to include some code to tell Access what to do once the user clicks a button in your message box.<br><br>For more about setting error traps and error-handling statements, have a read of Chapter 8, &quot;Handling Run-Time Errors,&quot; in the &quot;Building Applications with Microsoft Access 97.&quot; that is included in the valuepak on the &quot;Office&quot; cd. <br><br>Lightning<br><br>Constant &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description<br>acDataErrContinue Continues without displaying<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the Delete Confirm dialog box.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Setting the Cancel argument to <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;False and the Response argument to<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acDataErrContinue enables Microsoft<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Access to delete records without <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompting the user.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top