Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Basic Code in Microsoft Access ADP

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

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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