Solved

Compacting an Access2000 Database Problem.

Posted on 2002-04-25
6
164 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now