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

Access doesn't fully shut down

Status
Not open for further replies.

Smashie

Programmer
May 11, 2000
19
0
0
GB
Does anyone else ever experience a situation where you close Access from a button (docmd.quit) and then find that Access is still running in the background (preventing Access from re-opening). Both myself and Phooey have experienced this when using ADO and I thought I had tied it down to the SEEK method of a recordset.<br><br>Now I am not so sure since I sporadically get it when using MOVENEXT as an alternative.<br><br>I have now pulled all my hair out and am wondering if anybody else has experienced similar problems and would like to share their experiences (or ideally tell me why it happens!)<br><br>Many thanks
 
are you closing all of your tables and databases<br><br>.Close <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
DougP<br><br>Thanks for your interest. I hope you can help.<br><br>I am using the.seek method of the ADO.recordset object.<br>To do so I (1) Create a connection object (to the current project), (2) Create a new recordset. (3) Open the recordset using the connection created in step 1.<br><br>I then (.seek) the record I require and close the recordset, set recordset to nothing, close the connection and set that to nothing (I have also tried using combinations of these closures)<br><br>I had thought I had solved the problem by using rst.movenext in place of seek but I still seem to occassionally get Access staying open.<br><br>You asked if I have closed all my tables and databases. I believe I have closed everything I have opened. How can I tell what is open prior to exiting in order to ensure that I shut down properly?<br><br>Thanks for your help.
 
Is it possible to see your code maybe you are overlooking something.<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Here is the code...<br>============================================================<br>Private Sub Attempt_Logon_Click()<br><br>Dim cnnUser As ADODB.Connection<br>Dim rstUser As New ADODB.Recordset<br>Dim StrFind As String<br>Dim fltMainMenu As String<br><br>Set cnnUser = CurrentProject.Connection<br>Set rstUser = New ADODB.Recordset<br><br>With rstUser<br>&nbsp;&nbsp;&nbsp;&nbsp;.Index = &quot;UserName&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;.Open Source:=&quot;Users&quot;, _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ActiveConnection:=cnnUser, _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CursorType:=adOpenDynamic, _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LockType:=adLockReadOnly, _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options:=adCmdTableDirect<br>&nbsp;&nbsp;&nbsp;&nbsp;.Seek Array(Me![Username])<br>&nbsp;&nbsp;&nbsp;&nbsp;If .EOF Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Username and/or password incorrect.&quot; & Chr(10) & Chr(10) & &quot;Please try again.&quot;, vbExclamation<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attempted = attempted + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If attempted &gt;= 3 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Quit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me![Password].SetFocus<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set cnnUser = Nothing<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Trim(rstUser![Password]) &lt;&gt; Trim(Me![Password]) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Username and/or password incorrect.&quot; & Chr(10) & Chr(10) & &quot;Please try again.&quot;, vbExclamation<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attempted = attempted + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If attempted &gt;= 3 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Quit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me![Password].SetFocus<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set cnnUser = Nothing<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.OpenForm &quot;Main Menu&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Forms![Main Menu]![Username] = Me![Username]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Close acForm, &quot;logon&quot; 'this form<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End With<br><br>Set cnnUser = Nothing<br><br>End Sub<br>============================================================<br><br>The path causing concern is where the logon details are correct and 'Main Menu' is opened. The CLOSE button from the menu then leaves Access 'open' in the background. The .seek method was replaced by using movenext (etc) and this appeared to work although sporadic reoccurrences of Access staying open have since occurred. Note that the .seek method WILL work (i.e not leave Access open) if I replace the variable name with an actual value (such as &quot;Admin&quot;), but I obviously don't want to do this as it would defeat the object of the login form.<br><br>Code for CLOSING the app from the menu is as follows:<br>============================================================<br>Private Sub Exit_Button_Click()<br>On Error GoTo Err_Close_Click<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim CompactAnswer As Variant<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim fs As Object<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;CompactAnswer = MsgBox(&quot;Would you like to compact this database now?&quot;, vbYesNo, &quot;Compact&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;If CompactAnswer = &quot;6&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Hourglass True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Close acForm, &quot;Main Menu&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If fs.FileExists(&quot;W:\Sep_Reps\OldData.mdb&quot;) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fs.DeleteFile (&quot;W:\Sep_Reps\OldData.mdb&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DBEngine.CompactDatabase &quot;W:\Sep_Reps\SEPData.mdb&quot;, &quot;W:\Sep_Reps\OldData.mdb&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fs.CopyFile &quot;W:\Sep_Reps\OldData.mdb&quot;, &quot;W:\Sep_Reps\ComData.mdb&quot;, True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Hourglass False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set fs = Nothing<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.RunCommand acCmdExit<br>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf CompactAnswer = &quot;7&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.RunCommand acCmdExit<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Close<br><br>Exit_Close_Click:<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br><br>Err_Close_Click:<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox Err.Description<br>&nbsp;&nbsp;&nbsp;&nbsp;Resume Exit_Close_Click<br><br>End Sub<br>============================================================<br>Please note that Access stays 'open even if you quit Access from the menubar or the top right hand close button ('X').<br><br>Any ideas?<br><br>Thanks.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top