PC Review


Reply
Thread Tools Rate Thread

Close Database

 
 
New Member
Join Date: Mar 2010
Posts: 1
 
      29th Mar 2010
Hi,

I have been struggling with a problem for a while and am hoping someone can help me. I am working with ADO and also Access objects to transfer data between Excel and Access. I am experienced in Excel but newish to Access and very new to ADO etc.

Long story short when I open a connection I can't seem to close it.

Below is an example of the code (with queries taken out to simplify):

Sub TESTCONNECTION()
Dim Cnct As String
Dim Connection As ADODB.Connection
Dim dbPath As String
Dim DB_Name As String
Dim DBFullName As String
Dim DBTblName As String
Dim DBTblPath As String


DB_Name = Range("DBase_Name").Text

' Database information
If Range("config_DB_InDir").Value = True Then
DBFullName = ThisWorkbook.Path & "\" & DB_Name & ".mdb"
Else
DBFullName = Range("Database_Path").Text

End If

'Set database name here

Cnct = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBFullName & ";"
'Open connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct
OpenCurrentDatabase (DBFullName)


Connection.Close
CloseCurrentDatabase
Close
MsgBox "Complete"
End Sub

I've tried a range of close methods but the db seems to remain locked open.

NB I am using DoCmd.OpenQuery and also ADODB.Recordset type queries.

Any help would be great.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Excel data to database causing Database to Close. Hotwheelsrc51 Microsoft Access External Data 1 17th Jun 2008 04:48 PM
access opens database first time, close and retry database won't o =?Utf-8?B?Y29tcHVzZXIxMA==?= Microsoft Access 2 30th Jan 2007 04:19 PM
Close the Switchboard, Close the Database =?Utf-8?B?QXByaWwgS2xlaW4=?= Microsoft Access Forms 2 25th Aug 2006 08:22 PM
Database question - Database Open, Close Design =?Utf-8?B?TWFjY2E=?= Microsoft C# .NET 4 20th Sep 2005 10:01 PM
Close database on close form Kevin Sprinkel Microsoft Access Forms 5 7th Apr 2004 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:29 PM.