Results 1 to 3 of 3
  1. #1
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Calling DAO Close

    Should this be called after I run a query in VBA? Will this affect Access's access to this db, or is the close only in reference to the instance called\created by VBA?
    Code:
        Set db = CurrentDb()
        db.Execute "UPDATE Security SET Role='Deleted' WHERE ID=" & intID & ";"
        db.Close
        Set db = Nothing


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Only pertains to the declared object and the Close is not required. Access will discard the object when the procedure ends, although explicitly closing and clearing objects is considered 'best practice'. However, don't even need the db variable.

    CurrentDb.Execute "UPDATE ..."
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The rule I learned was:

    If you open it, close it
    If you create it, destroy it.


    Example:
    Code:
       Dim db As DAO.Database
       Dim rs As DAO.Recordset
    
       Set db = CurrentDb()
       Set rs = db.OpenRecordset("SavedQuery")
       If Not (rs.BOF And rs.EOF) Then
    
          ' do something here
    
       End If
    
       rs.Close               ' opened it, so close it
       Set rs = Nothing   ' created it, so destroy it
       '   db.Close          ' Did not open it, so do not close it
       Set db = Nothing   ' created it, so destroy it
    
    End Sub

    BTW, "Currentdb.Execute " is faster for action queries because it bypasses Access and is executed in/by Jet. But if you have a lot of calls to open or manipulate recordsets, it is faster to use the "Set db = CurrentDb()" construct.



    My $0.02.......

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calling Error
    By drunkenneo in forum Programming
    Replies: 6
    Last Post: 09-12-2013, 01:32 PM
  2. Calling and exe from code
    By drunkenneo in forum Access
    Replies: 1
    Last Post: 09-03-2013, 05:45 AM
  3. Calling previous value to add with new value
    By 2skannan in forum Programming
    Replies: 3
    Last Post: 01-23-2013, 11:33 PM
  4. Replies: 2
    Last Post: 06-20-2011, 03:10 PM
  5. calling function
    By ManvinderKaur in forum Programming
    Replies: 3
    Last Post: 07-22-2010, 10:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums