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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Exit Code

Status
Not open for further replies.

billmeye

Technical User
Dec 24, 2004
24
US
I am using the ON EXIT event function to evaluate a field to ensure the user has entered data. If the user does not enter data, a message is shown and I reset the focus back to the field. My problem is when the user decides to not complete the record and closes the form, they are bombarded with the message telling them to enter data in the field. This will happen a couple of times and then the form will close.

Does anyone know if I can bypass my ON EXIT event when the form is closed? Thanks.
 
How aye ya billmeye . . . . .

Move your code to the [blue]BeforeUpdate Event[/blue] of the form. Be sure to add [purple]Cancel = True[/purple] just [blue]before or after[/blue] the [blue]MsgBox[/blue] function.

Be aware: if the record is not saved when you close, [blue]an additional system message[/blue] advising the record can't be saved, [blue]will be raised.[/blue]

If you have any problems . . . post back your code . . .

Calvin.gif
See Ya! . . . . . .
 
Thanks TheAceMan1 for the suggestion. I tried moving the code to the BeforeUpdate event of the form but it did not change the result, I still received the msg regarding the field required data and I also did get 'record can't be saved' msg.

Here is my code:

Private Sub Patient_Name_Exit(Cancel As Integer)
On Error GoTo fError
If Me.Patient_Name = "" Then
MsgBox "Please select a Patient to begin entering the Evaluation Information.", vbOKOnly
Me.Evaluation__.SetFocus
Me.Patient_Name.SetFocus
Else:
End If
Exit Sub

fError:
MsgBox Err.Description
End Sub

What I really need to be able to do is force the user to have to enter data into the 'Patient Name' on the master form field prior to entering data into the remaining fields on several subforms. Patient Name is my database Primary Key. It's great knowing there is so much experience willing to lend a hand. Thanks for your help.
 
billmeye . . . . .

Make sure [blue]Patient_Name[/blue] is first in your [purple]Tab Order[/purple], then try the following:
Code:
[blue]Private Sub Patient_Name_Exit(Cancel As Integer)
   If Trim(Me.Patient_Name & "") = "" Then
      MsgBox "Please select a Patient to begin entering the Evaluation Information.", vbOKOnly
      Cancel=True
   End If
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks again for the suggestion, unfortunately it yields the same result as I was getting. Is there simply some VBA code that's something along the line of 'ON FORM CLOSE' so I can bypass my data checking? I am very new to using VBA and I am trying to use the MSDN on line guide with little success. Thanks.
 
billmeye . . . . .

I ran a few simulations (finally) with different events, and [blue]as long as the current record is in edit mode[/blue] (pencil icon) [purple]you can't get around a minimum of two messages.[/purple] Yours and a system message because your attempting to close the form.

[blue]Closing a form is a system function[/blue] that takes priority and [blue]always attempts to save the current record[/blue] (if in edit mode). [purple]This is the conflict[/purple] . . . . our VBA interferes with saving and is considered an error. Hence the system message.

Currently attempting other methods . . . if anything comes thru I'll post back . . .


Calvin.gif
See Ya! . . . . . .
 
Thanks. What I'm really trying to do is keep things looking clean in case a user opens a form with the intention of adding a record, but then at the last minute decides not to. It's not something that should happen, really.

Thanks for the help.
 
billmeye . . . . .

Actually this is something thats [blue]not as bad as it appears.[/blue] It certainly will teach the user to enter [purple]Patient_Name![/purple] ;-)

There is a way to delete the record, but you'll still have one message to deal with. Besides . . . . . I'll allow users to add records . . . . [purple]Never to Delete![/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top