Solved

Visual Basic Code in Microsoft Access ADP

Posted on 2013-05-20
5
559 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 47

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

726 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