Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / February 2006

Tip: Looking for answers? Try searching our database.

verify text boxes when users click close window button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BillyRogers - 01 Feb 2006 20:40 GMT
I have a form that people use and sometimes they click the x in the upper
right hand corner of the form to close it.  I want to validate that certain
text boxes are not blank and if they are have a message box pop up and the
close action stopped.

I've been trying to code this and nothing seems to work.

what code should i use and what event should i put it in?

thanks
BruceS - 02 Feb 2006 04:51 GMT
Billy,

Set the form's "CloseButton" property to "No".  This deactivates the "x" and
makes them use your button to close the form.

Note that if they are allowed to close the form using Access controls in the
menu bar or by right-clicking, your "Close Button" logic will still not be
processed.

Bruce

> I have a form that people use and sometimes they click the x in the upper
> right hand corner of the form to close it.  I want to validate that certain
[quoted text clipped - 6 lines]
>
> thanks
Kevin K. Sullivan - 02 Feb 2006 15:54 GMT
BillyRogers,

Option one is to use data validation rules in your table (strongest) or
in your form.  Another option, especially if the validation is
complicated and depends on the values of multiple fields is to work with
the Form's Unload event. If your validation fails, set the Cancel
parameter to True and the form won't close.  This event fires whether
you close via the Close button, DoCmd.Close, closing Access, etc.

air code sample

Private Sub Form_Unload(Cancel as Integer)

'validate form before closing is allowed

If Len(txtNonBlank & "") = 0 then
  Cancel = True
  MsgBox "You must enter a value for the field NonBlank.", vbOKOnly
  txtNonBlank.SetFocus
  Exit Sub
End if

If Len(txtNeedsText & "") = 0 then
  Cancel = True
  MsgBox "You must enter a value for the field NeedsText.", vbOKOnly
  txtNeedsText.SetFocus
  Exit Sub
End if

If txtMinimum >= txtMaximum then
  Cancel = True
  MsgBox "Minimum must be less than Maxiumum", vbOKOnly
  txtMinimum.SetFocus
  Exit Sub
End Sub
---------

HTH,

Kevin
> I have a form that people use and sometimes they click the x in the upper
> right hand corner of the form to close it.  I want to validate that certain
[quoted text clipped - 6 lines]
>
> thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.