Solved

Visual Basic Code in Microsoft Access ADP

Posted on 2013-05-20
5
548 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 45

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now