Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compacting an Access2000 Database Problem.

Posted on 2002-04-25
6
Medium Priority
?
171 Views
Last Modified: 2010-05-02
I am using the following code to compact a database.
If the mdb file has not been opened. ie. This is e 1st thing done when opening the program. It works fine!!
---
 Label1 = "Compacting Databases"
    Label1.Refresh

    Dim Fsys As New FileSystemObject
    Dim OutFile As String
    Dim Infile As String
    Infile = App.Path & "\" & "awol.mdb"
    OutFile = App.Path & "\" & "awolx.mdb"

    If Len(Dir(OutFile)) > 0 Then
        Kill OutFile
    End If
   
    DBEngine.Workspaces(0).Close  

    DBEngine.CompactDatabase Infile, OutFile, ";pwd=admin", , ";pwd=admin"

    If Len(Dir(Infile)) > 0 Then
        Kill Infile
    End If

    Fsys.CopyFile OutFile, Infile, overwrite
------------------------------------------------

BUT...!@!@!@!@ If i have had the mdb file open under ADO, and close the connection , and then try to run the above code, i get an error You attempted to open...allready exclusivery open  etc... error 3356.

If i go totally out of the program, and then come back in, and run the compact, all ok.


How do you TOTALLY  !@@!!@ close a database so i can compact it.

I am opening as follows.

Dim StrDBFileName As String
    Dim StrCnn As String

    StrDBFileName = Trim(App.Path) & "\Awol.mdb"
    StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=admin;Data Source=" & StrDBFileName
    Set cnn = New ADODB.Connection
    cnn.Open StrCnn

Set rs = New ADODB.Recordset
    Set rs2 = New ADODB.Recordset
   
    rs.Open "wol", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
    rs2.Open "wolid", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect

----
rs.Close
rs2Close
cnn.Close
                                                                                                                  Set cnn = Nothing
DBEngine.Workspaces(0).Close  

After all these close's, the compact still will not work, an i missing something???

===================================================

Appreciate any help.



   
0
Comment
Question by:kennedymr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6969924
DBEngine.Workspaces(0).Close  is DAO not ADO!
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 320 total points
ID: 6969936
So, you are melting both technologies, uh?
maybe is a problem with timming, just a guess.
0
 

Author Comment

by:kennedymr
ID: 6969942
I agree an error.
I only included DBEngine.Workspaces(0).Close  , at the last moment in a lapse of brainpower.!! After 2 hours of this thing not working.
0
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!

 

Author Comment

by:kennedymr
ID: 6969956
Suddenly the whole thing is working.

The only thing i did was go into Access and open the database and then go back out.

Not sure if this has anything to do with it, BUT all is OK now....Hopefully forever!!!


0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6969970
Well, i would like to say a couple of things:
1)Thanks for "A" grade.
2)do you use filesystem only to use in
Fsys.CopyFile OutFile, Infile, overwrite
?
If so, you could use name function or FileCopy one
3)change this:
If Len(Dir$(OutFile)) > 0 Then
    Kill OutFile
End If
to this
If Dir$(OutFile)<>"" Then
    Kill OutFile
End If
I think, why to use one more function where it is not necessary?
;)
Cheers
0
 

Author Comment

by:kennedymr
ID: 6969979
Appreciate you help.
Did not like to give a "C" grade !!!, even under these circumstances.

I use fsys. for both copying,deleting
Will give filecopy a go, as most of the fsys. is for copying files.


regards
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question