auto exit of custom form

  • Thread starter Thread starter dale
  • Start date Start date
D

dale

What is the command or procedure to automatically exit a
form? On my custom form when a certain condition occurs,
I want to automatically exit the form. I have not been
able to find anything that resembles this.

Thanks in advance,

Dale
 
Item.Close

You'll need the number for the close argument as well.

Item.Close (0) 'Save
Item.Close (1) 'Discard
Item.Close (2) 'Prompt for save

--
Patricia Cardoza
Outlook MVP
Author - Special Edition Using Microsoft Office Outlook 2003
Lead Author - Access 2003 VBA Programmer's Reference
Author - Absolute Beginner's Guide to Microsoft OneNote 2003

http://blogs.officezealot.com/cardoza
 
Sorry to but in on the thread, but I have a similar question:
If a user clicks the "X" to close the form, is there an event or condition
like the "QueryUnload" in VB that I can use to put some code before the form
actually exits?
 
Not really. What you could do, is put code in the Item_Close event. So for
example, if you want your users to click a command button to close the form,
create a global variable. (You create a global variable by Dimming it at the
top of the code window outside of any subs or functions).

Then when your users click the Command button, set the value of the global
variable to something...say 1.

Sub cmdButton_Click()

globalvariable = 1
Item.Close 0

End Sub


Then in the Item_Close event do something like this:

Function Item_Close()

If globalvariable = 1 then
'do nothing
Else
Exit Function
End If

End Function

Basically, this tells the form that you don't want to close unless your user
clicks the command button.

--
Patricia Cardoza
Outlook MVP
Author - Special Edition Using Microsoft Office Outlook 2003
Lead Author - Access 2003 VBA Programmer's Reference
Author - Absolute Beginner's Guide to Microsoft OneNote 2003

http://blogs.officezealot.com/cardoza
 
Back
Top