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!

Application.Quit - Runtime Error 2046

Status
Not open for further replies.

grobermatic

Technical User
Dec 21, 2002
153
GB
Hi,

I'm using the following code to log users out of my database:

Code:
Function LogOff(UserID As String, dteLogon As Date, dteTime As Date)
On Error GoTo err_LogOff

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim intlogID

    Set db = CurrentDb
    Set rst = db.OpenRecordset("tbluseagelog", dbOpenDynaset)
    
    intlogID = DLookup("[LogID]", "tblUseagelog", "userid='" & UserID & "'" & " And logondate=#" & dteLogon & "#" & " And logofftime=null")
    
    If IsNull(intlogID) Then Exit Function
            
    With rst
    .FindFirst "[logID] = " & intlogID
    .Edit
    !logofftime = Time
    .Update
    End With
    
Set db = Nothing
Set rst = Nothing

Application.Quit

'CloseAllForms "frmUserDetails"
'DoCmd.OpenForm "frmQuit", , , , , acDialog

exit_LogOff:
Exit Function

err_LogOff:
If Err.Number = 2046 Then
Else
    MsgBox Err.Number & " " & Err.Description
    Resume Next
End If

        
End Function

I always get Runtime Error 2046,

The Command Or Action 'Quit' isn't available now

This then prevents the database from closing. I have some code which runs at db startup which disables the application close button (top right) - I originally thought that this was the cause of the error, but having removed this completely... it still happens.

I tried putting the APPLICATION.QUIT line begind a button on a blank form and it worked fine. I therefore thought I could workaround it by making the above code open a dialog box which I could then use to execute the APPLICATION.QUIT line. However this produced the error aswell.

Any help of suggestions would be gratefully received.

Thanks in advance

Craig


--------------------------------------------------------------------------------------------------------
"Time-traveling is just too dangerous. Better that I devote myself to study the other great mystery of the universe: Women!" .. Dr E. Brown (1985)
 
Have you tried to Quit after closing the form ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi,

I setup a function to close all open forms except one, which I kinda wanted to keep open, however the error still happened.

After you post I changed it so that it closes all forms before running APPLICATION.QUIT and it did work.

The confusing thing is that I have other databases which will allow this command to execute while other forms are open.

Any ideas what could be the problem here and why APPLICATION.QUIT will not run with these forms open? The open form is a hidden form which was opened with the POPUP property set to TRUE as when viewed its on the top of a maximised form and I wanted it to appear as a dialog on top.

Any further comments owuld be appreciated

Thanks

Craig

--------------------------------------------------------------------------------------------------------
"Time-traveling is just too dangerous. Better that I devote myself to study the other great mystery of the universe: Women!" .. Dr E. Brown (1985)
 
... actually the error still occurs, however as I have the error handler in place, it is ignored and the database still closes.

When I took the handler out it caused the error with an OK button... when clicked the db closed down.

Still puzzled!!

--------------------------------------------------------------------------------------------------------
"Time-traveling is just too dangerous. Better that I devote myself to study the other great mystery of the universe: Women!" .. Dr E. Brown (1985)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top