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
srikanthnamaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.