Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Copy a database

Discussion in 'Information Technology' started by StuJol, Jul 28, 2006.

Tags:
  1. StuJol

    StuJol
    Expand Collapse
    Guest

    im currently using the following code to compact and repair my BE database on
    close of my FE.

    Public Sub cmdCompact_Click()
    On Error GoTo Err_cmdCompact_Click


    'Compact the Back-End database to a temp file.
    DBEngine.CompactDatabase "C:\Program Files\Job Manager\Database\Job
    Manager Database.mdb", "C:\Program Files\Job Manager\Database\Job Manager
    Database Temp.mdb"

    'Delete the previous backup file if it exists.
    If Dir("C:\Program Files\Job Manager\Database\Job Manager Database.bak")
    <> "" Then
    Kill "C:\Program Files\Job Manager\Database\Job Manager Database.bak"
    End If

    'Rename the current database as backup and rename the temp file to the
    original file name.
    Name "C:\Program Files\Job Manager\Database\Job Manager Database.mdb" As
    "C:\Program Files\Job Manager\Database\Job Manager Database.bak"
    Name "C:\Program Files\Job Manager\Database\Job Manager Database
    Temp.mdb" As "C:\Program Files\Job Manager\Database\Job Manager Database.mdb"

    'Copy the backup database to the backup directory.
    Name "C:\Program Files\Job Manager\Database\Job Manager Database.bak" As
    "C:\Program Files\Job Manager\Database\backup\Job Manager Database " &
    Format(Date, "dddd, mmm d yyyy") & ".bak"


    Exit_cmdCompact_Click:
    Exit Sub

    Err_cmdCompact_Click:
    MsgBox Err.Description & " " & Err.Number
    Resume Exit_cmdCompact_Click

    End Sub

    this code creattes a database.bak file which im trying to copy to a new
    directory but are unable to. I've used the file copy method but just keep
    getting errors and i've used the rename method to try and save file in a
    different directory but that doesnt work either.

    Any ideas please?
     
  2. Loading...

    Similar Threads Forum Date
    Opinion Akal Takht concerned on drug addiction, copying during exams Breaking News Nov 5, 2013
    SciTech New Quantum Dot Technique Combines Best of Optical and Electron Microscopy Breaking News Jun 17, 2013
    India Copy of 48th Rreport of 'LOKPAL BILL 2011' Presented in Parliament Breaking News Dec 10, 2011
    Bhagats Sheikh Farid Copyright? History of Sikhism Nov 14, 2011
    Christianity Public library find is only surviving copy of rebel hymn book Interfaith Dialogues Jan 8, 2011

  3. strive4peace

    strive4peace
    Expand Collapse
    Guest

    Hi Stu,

    Make sure your temp.mdb file is also deleted before you try
    to overwrite it. Also, try removing the spaces from the
    filename. If you want "space", use the underscore character
    instead.

    Job_Manager_Database_Temp.mdb

    after you Kill a file, use

    DoEvents

    DoEvents is used to make VBA pay attention to what is
    currently happening and look to see if the OS (Operating
    System) has any requests.

    ie: if you have a loop and want to be able to BREAK it with
    CTRL-BREAK, put DoEvents into the loop

    DoEvents will also update values written to a form by a
    general procedure or code behind another form or report

    A DoEvents is done when you use MsgBox, or are stepping
    through code (since it has to pay attention to the keyboard)

    It is a good way to say, "Wake Up!"
    ~~~~~~~~~

    also, since you are renaming the db, make sure you have no
    open forms, reports, quusing it.

    Warm Regards,
    Crystal
    Microsoft Access MVP 2006

    *
    Have an awesome day ;)

    remote programming and training
    strive4peace2006 at yahoo.com

    *

    StuJol wrote:
    > im currently using the following code to compact and repair my BE database on
    > close of my FE.
    >
    > Public Sub cmdCompact_Click()
    > On Error GoTo Err_cmdCompact_Click
    >
    >
    > 'Compact the Back-End database to a temp file.
    > DBEngine.CompactDatabase "C:\Program Files\Job Manager\Database\Job
    > Manager Database.mdb", "C:\Program Files\Job Manager\Database\Job Manager
    > Database Temp.mdb"
    >
    > 'Delete the previous backup file if it exists.
    > If Dir("C:\Program Files\Job Manager\Database\Job Manager Database.bak")
    > <> "" Then
    > Kill "C:\Program Files\Job Manager\Database\Job Manager Database.bak"
    > End If
    >
    > 'Rename the current database as backup and rename the temp file to the
    > original file name.
    > Name "C:\Program Files\Job Manager\Database\Job Manager Database.mdb" As
    > "C:\Program Files\Job Manager\Database\Job Manager Database.bak"
    > Name "C:\Program Files\Job Manager\Database\Job Manager Database
    > Temp.mdb" As "C:\Program Files\Job Manager\Database\Job Manager Database.mdb"
    >
    > 'Copy the backup database to the backup directory.
    > Name "C:\Program Files\Job Manager\Database\Job Manager Database.bak" As
    > "C:\Program Files\Job Manager\Database\backup\Job Manager Database " &
    > Format(Date, "dddd, mmm d yyyy") & ".bak"
    >
    >
    > Exit_cmdCompact_Click:
    > Exit Sub
    >
    > Err_cmdCompact_Click:
    > MsgBox Err.Description & " " & Err.Number
    > Resume Exit_cmdCompact_Click
    >
    > End Sub
    >
    > this code creattes a database.bak file which im trying to copy to a new
    > directory but are unable to. I've used the file copy method but just keep
    > getting errors and i've used the rename method to try and save file in a
    > different directory but that doesnt work either.
    >
    > Any ideas please?
     
  4. Ron2006

    Ron2006
    Expand Collapse
    Guest

    How may FEs are there accessing the BE?

    Are any of the FEs still attached to the BE when this is trying to
    run.?

    How do you know everyone is out?

    Ron
     
  5. Ron2006

    Ron2006
    Expand Collapse
    Guest

    How may FEs are there accessing the BE?

    Are any of the FEs still attached to the BE when this is trying to
    run.?

    How do you know everyone is out?

    Ron
     

Share This Page