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

closing a form

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I have a form with text fields so a user can enter information. I am trying to make this form more robust so if the user has some information entered on the form and he clicks the close button in the top right corner, I want to ask the user if he really wants to close the form. I have the following code in the Form_Close() section of the code:

Private Sub Form_Close()

If (txtName.text = "") or IsNull(txtName.text) Then
formchange=true
End if

If (formchange=true) Then
Dim Response as integer
Response = MsgBox("Do you really want to close?", vbYesNoCancel)
...
End if

End Sub


When I test this out, I get an error saying one of my fields can't be null because the required property is set to true. Access tells me that I can't save this record at this time, but do I want to close the database object anyway.

After all those error messages, THEN my code will run. How can I bypass all of that? Any ideas? Thanks!!
 
Check into the Dirty property of the form. It's in help... Terry M. Hoey
 
Ok, but where do I place the following code? It doesn't seem to work if I put it in the Form_Close() event...

If (Me.Dirty = true) then
'Ask if the user really wants to close
Else
'Just close the form
End if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top