?
Solved

Visual Basic Code in Microsoft Access ADP

Posted on 2013-05-20
5
Medium Priority
?
563 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 58
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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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 48

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…
Suggested Courses

743 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