Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003

    Arrow Unanswered: close database in vb ?

    If I declare a db as the current database, do I have to close it or does it matter if I close it or just leave it alone? I have a recordset and when I'm done with the record set I close it and set it to nothing, and I'm wondering if I have to do the same for the database.

    Dim dbs As DAO.Database
    Dim rdset As DAO.Recordset
    Dim sqlStr As String
    sqlStr = " select * from contact"
    Set dbs = CurrentDb()
    Set rdset = dbs.OpenRecordset(sqlStr)
    If rdset.EOF Then
    End If
    Set rdset = Nothing


  2. #2
    Join Date
    Apr 2003
    I never close my database after I have run it in VBA. I think when the code reach to the 'END SUB', it would close the connection to the database. I have never had problem with it, on not closing it though.

  3. #3
    Join Date
    Sep 2003
    Lancashire, UK
    It is good practice to close the database object. It can cause problems in some conditions, though not often in normal practice. It is good practice to close all open objects when they are no longer needed, "just in case"
    Another point is that set object = nothing and object.close are in effect different methods of doing the same thing, so only one or the other is necessary, whichever you prefer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts