How to close out of a form without displaying msgbox message

How to close out of a form without displaying msgbox message

Post by Pamela via » Sat, 02 Jul 2005 23:52:31


This is driving me nuts. Here is what I want to do:

I have a control on a form which is a required text field for data entry. On
the Lost Focus event I placed code to alert the user to enter text if the
field is left null. Also on this form is a button which executes a macro to
exit out of access. But...when in "add record" mode, and I want to end the
application, when I click the exit button to exit access, the first field
loses focus & so kicks off the error message "please enter name" before
exiting the program.

The field (Dr_Grp) is designed to have focus when the user clicks the add
button to add a new record. I want the focus to remain on this field for
usability purposes, but I also want to be able to give the user a user
friendly message for the required field if they tab out of it. Is there a
clever (or not so clever) way to do both without having to move to a previous
record or something before closing out? I understand what is happening, when
I exit the program, the Dr_Grp field loses focus kicking off the message.
I'm fairly new to VB...

Thanks!

--
Message posted via http://www.yqcomputer.com/
 
 
 

How to close out of a form without displaying msgbox message

Post by QnJpYW » Sun, 03 Jul 2005 01:09:01

You could insert this into the LostFocus event (see below for an even better
way, though):

If Not Me.Dirty then
MsgBox "Please enter the name.", vbCritical, "Missing information"
End if

This will show the message only if something has been input elsewhere in the
record. "Dirty" means that it is either a blank new record or an existing
record on which nothing has changed since the user opened it.

Alternatively (probably preferably), you could move your code from the
LostFocus of the control to the BeforeUpdate of the form. This event fires
before the record is saved, but not when the form is closed without any
changes.

If IsNull(Dr_Grp) Then
MsgBox "Please enter the name.", vbCritical, "Missing information"
Cancel = True 'cancels the save
End If

This transfers the "checkpoint" from when the user exits the field to the
point when the entire record will be saved.

 
 
 

How to close out of a form without displaying msgbox message

Post by Pamela via » Sun, 03 Jul 2005 02:47:19

Hi!

Thanks for your reply. The second method appears to be the one I want (code
placed in before update event), however, the message box does not appear...
but the cursor stays in the field until data is entered like I wanted. Any
idea on why the message box doesn't appear? Sorry - still a bit rusty on
forms programming - it's been 2 years since I've even touched it, & that was
PL/SQL in Oracle, not VBA in MS Access. Thanks for the refresher on "Dirty".
:-)

Thanks again.

--
Message posted via http://www.yqcomputer.com/
 
 
 

How to close out of a form without displaying msgbox message

Post by Pamela via » Sun, 03 Jul 2005 03:14:00

Ah! Thanks for your help. I found a slick solution which works for all the
text boxes here:
http://www.yqcomputer.com/
exactly what I need. :)

Thanks again!

--
Message posted via http://www.yqcomputer.com/