Application.quit

D

D

I am trying to let the user exit out of the database.
When I run the module, an error message occurs 'The
command or action 'Quit' isn't available at now.'
 
D

D

I just have a form that is open. I have a shortcut menu
item calling a function. Below is the function.

Public Function ExitCurrentDB()
Dim frm As Form

For Each frm In Forms

DoCmd.Close acForm, frm.Name, acSaveNo

Next frm



Application.Quit






End Function
 
A

Allen Browne

You may find it better to loop backwards through Forms collection: some
collections get confused if earlier items are disappearing while the loop is
running.

There is a bug with the Close method that can cause a form to *silently*
lose the user's edits if the record can't be saved (e.g. required field
missing). To avoid that, an explicit save is needed. If the form is unbound,
it has no Dirty property, so we need to test for that first.

If that still doesn't work, it may be worth considering the situation in
which the shortcut menu is being fired. Beyond that, it may be a matter of
checking that the code works on a single basic form in another database, and
if so, tracking what is open that is preventing the close.

Suggestion to try:

Dim lng As Long
Dim frm As Form

For lng = Forms.Count -1 To 0 Step -1
Set frm = Forms(lng)
If HasProperty(frm, "Dirty") Then
If frm.Dirty Then
frm.Dirty = False
End If
End If
DoCmd.Close acForm, Forms(lng).Name, acSaveNo
Next
Set frm = Nothing
'Close anything else you opened.
'Dereference any other objects.
Application.Quit

Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant

On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top