Solved

Compacting an Access2000 Database Problem.

Posted on 2002-04-25
6
168 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 80 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 61
Microsoft Access combo box help 2 52
using web browser with BING 40 136
Fastest way to find and count same items VB6 16 43
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 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