Solved

Visual Basic Code in Microsoft Access ADP

Posted on 2013-05-20
5
558 Views
Last Modified: 2013-06-16
We are using Access ADP's to serve reports to our end users. We recently moved to SQL Server 2008 and have noticed that when closing our Access ADP's they often hang. Further investigation showed multiple write accoss the network to close the ADP when hitting the Exit button. Below is the code that we use to close the ADP. I was wondering if there is a better way to close the Access ADP. Since we do not write data back to the database on close I simply wish to kill the Access Session.

Private Sub ExitMainForm_Click()
On Error GoTo Err_ExitMainForm_Click

    DoCmd.Quit

Exit_ExitMainForm_Click:
    Exit Sub

Err_ExitMainForm_Click:
    MsgBox err.Description
    Resume Exit_ExitMainForm_Click
    
End Sub

Open in new window

0
Comment
Question by:mburk1968
  • 2
5 Comments
 
LVL 57
ID: 39180944
Not closing no, but in your code, close anything you open (i.e. a recordset) and set all object variables to nothing.

  VBA should do cleanup for you when things go out of scope, but often it doesn't.

BTW, only other way to exit is Application.Quit, but I've found using that often causes applications to hang.   If I use DoCmd.Quit (old style), no hangs.

Jim.
0
 

Author Comment

by:mburk1968
ID: 39180976
Jim,

Can you provide me a sample of what the code should look like. I guess I should have said that I am not  a VB programmer and the person who wrote this code is no longer with our company.
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39181272
Below is an example of how routines should be structured.   Also make sure your up to date on service packs.  Bugs in Access will cause hangs.

Jim.


  Dim cn as ADODB.Connection
  Dim rst as ADODB.Recordset

  On Error Goto MyProcedure_Error

   Set cn = CurrentProject.Connection
   Set rst = Cn.Execute("SELECT * FROM Employees")
 
    ' Do some stuff

    ' Note that you can close things and set to nothing in the main part of the procedure
    ' or simply wait for the exit.  But if you do this in the main part of the code,
    ' you still need to do it within the exit because an error at any point may leave things
   ' open
    rs1.close
    Set rst = Nothing

    ' Do some more stuff

MyProcedure_Exit:
    ' Cleanup

    On Error Resume Next

    ' Need to close the recordset and set to nothing the object variable.
    rst.close
    Set rst = Nothing

   ' Note here, there is no close because you didn't open the connection, but rather
   ' used the projects connection
    Set cn = nothing

MyProcedure_Error:
    Msgbox "unexpected error"
    Resume MyProcedure_Exit
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39251081
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question