Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Unable to kill access MDB file at run time

Hi,

I am using DAO 3.6 to create an access MDB at the run time and populating the table. When i try to kill the mdb for next round of operations I get 'Path/File access error'. I am closing the database everytime I open it. I don't want to close my application for each operation.

How to avoid this error ? Your help is highly appreciated
0
srikanthnama
Asked:
srikanthnama
1 Solution
 
_Merlin_Commented:
Don't use the dataconnection control. Link to your database using code. That way you can unlink the database and kill it, rename it or whatever.

example:

Public cn_MyDb As ADODB.Connection
dim str_DatabasePath as string

Set cn_MyDb = Nothing
Set cn_MyDb = New ADODB.Connection

str_DatabasePath = "C:\Database\MyDb.mdb"
' You can assign the databasepath a value by using a common dialog and store the value in the registry for next runs.
' If the database can't be found, call the commondialog again to locate it and store the new value in the registry.

cn_MyDb.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & str_DatabasePath

' Perform actions to the db.

' disconnect the database
Set cn_MyDb = Nothing

' Now you can kill it or whatever.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
If you only use Access, you need 2 "databases": 1 for the front-end, and one for the data store.
0
 
BalsheCommented:
see this sub

Sub CompactDB()
Dim DbName As String
DbName = Db2.Name
Db2.Close
Caption = "Compacting"
Dim X As String, DbFile As String, Dbpath As String
Dim pos As Long
X = DbName
pos = InStrRev(X, "\")
DbFile = Mid(X, pos + 1, Len(X))
Dbpath = Mid(X, 1, pos)
X = Dbpath & "XX" & DbFile
DBEngine.CompactDatabase DbName, X
Kill DbName
Name X As DbName
Set Db2 = DBEngine.OpenDatabase(App.Path & "\School.mdb")
End Sub
0
 
cerebralpcCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept  _Merlin_  comment as answer.

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
cerebralPC
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now