How to copy a mdb file with VBA code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon van Beek

    How to copy a mdb file with VBA code

    Dear reader,



    How can I make a copy from a database which is in use.

    If an mdb database is in use Access opens a small file with the extension
    ldb.

    This ldb file prohibits the execution of the following copy instruction:



    FileCopy SourceFile, DestinationFile



    The question is now, is there a possibility to make a copy of an in used mdb
    file with a VBA code instruction.



    Thanks for any help.

    Kind regards,

    Simon


  • lyle fairfield

    #2
    Re: How to copy a mdb file with VBA code

    "Simon van Beek" <SvanBeekNL@Ver satel.nlwrote in
    news:48e1df93$0 $20633$bf4948fe @news.tele2.nl:
    How can I make a copy from a database which is in use.
    >
    If an mdb database is in use Access opens a small file with the
    extension ldb.
    >
    This ldb file prohibits the execution of the following copy
    instruction:
    Assuming Access Version >=2000

    try

    With CurrentProject
    Shell "cmd /c copy """ & .FullName & """ """ & Replace(.FullNa me, .Name,
    "NewName.mdb""" ), vbHide
    End With

    The text "Shell ... vbHide" is one line of code.

    --
    lyle fairfield

    Comment

    • GrafixSoft@gmail.com

      #3
      Re: How to copy a mdb file with VBA code

      On 29 Sep, 22:42, "Simon van Beek" <SvanBee...@Ver satel.nlwrote:
      Dear reader,
      >
      How can I make a copy from a database which is in use.
      >
      If an mdb database is in use Access opens a small file with the extension
      ldb.
      >
      This ldb file prohibits the execution of the following copy instruction:
      >
      FileCopy SourceFile, DestinationFile
      >
      The question is now, is there a possibility to make a copy of an in used mdb
      file with a VBA code instruction.
      >
      Thanks for any help.
      >
      Kind regards,
      >
      Simon
      Try this:

      Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
      lpExistingFileN ame _
      As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long)
      As Long

      Sebastian C.

      Comment

      • David W. Fenton

        #4
        Re: How to copy a mdb file with VBA code

        GrafixSoft@gmai l.com wrote in
        news:c0683fed-eb9c-4e9b-94ff-7cbc0cf81d34@z6 6g2000hsc.googl egroups.co
        m:
        Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
        lpExistingFileN ame _
        As String, ByVal lpNewFileName As String, ByVal bFailIfExists As
        Long) As Long
        This is *terrible* advice. All it does it get you around the very
        smart prohibition hardwired into Access that prevents copying of an
        open file. If the file is open, you can't guarantee that the result
        will not be corrupt (or in an inconsistent but noncorrupt state) no
        matter what method you use to copy via the file system.

        The only way to safely copy is through Jet commands. Code for that
        has been posted in the Access newsgroups many, many times, and
        should be easily found via searching Google Groups.

        --
        David W. Fenton http://www.dfenton.com/
        usenet at dfenton dot com http://www.dfenton.com/DFA/

        Comment

        • lyle fairfield

          #5
          Re: How to copy a mdb file with VBA code

          "David W. Fenton" <XXXusenet@dfen ton.com.invalid wrote in
          news:Xns9B29E88 1DAA52f99a49ed1 d0c49c5bbb2@74. 209.136.94:
          GrafixSoft@gmai l.com wrote in
          news:c0683fed-eb9c-4e9b-94ff-7cbc0cf81d34@z6 6g2000hsc.googl egroups.co
          m:
          >
          >Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
          >lpExistingFile Name _
          >As String, ByVal lpNewFileName As String, ByVal bFailIfExists As
          >Long) As Long
          >
          This is *terrible* advice. All it does it get you around the very
          smart prohibition hardwired into Access that prevents copying of an
          open file. If the file is open, you can't guarantee that the result
          will not be corrupt (or in an inconsistent but noncorrupt state) no
          matter what method you use to copy via the file system.
          >
          The only way to safely copy is through Jet commands. Code for that
          has been posted in the Access newsgroups many, many times, and
          should be easily found via searching Google Groups.
          I can't find this, David. I tried various combinations of copy, jet, open,
          file, save and replicate.

          Please, post code showing how you would do it.

          --
          lyle fairfield

          Comment

          • GrafixSoft@gmail.com

            #6
            Re: How to copy a mdb file with VBA code

            On 1 Oct, 05:51, "David W. Fenton" <XXXuse...@dfen ton.com.invalid >
            wrote:
            GrafixS...@gmai l.com wrote innews:c0683fed-eb9c-4e9b-94ff-7cbc0cf81d34@z6 6g2000hsc.googl egroups.co
            m:
            >
            Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
            lpExistingFileN ame _
            As String, ByVal lpNewFileName As String, ByVal bFailIfExists As
            Long) As Long
            >
            This is *terrible* advice. All it does it get you around the very
            smart prohibition hardwired into Access that prevents copying of an
            open file. If the file is open, you can't guarantee that the result
            will not be corrupt (or in an inconsistent but noncorrupt state) no
            matter what method you use to copy via the file system.
            >
            The only way to safely copy is through Jet commands. Code for that
            has been posted in the Access newsgroups many, many times, and
            should be easily found via searching Google Groups.
            >
            --
            David W. Fenton                  http://www.dfenton.com/
            usenet at dfenton dot com    http://www.dfenton.com/DFA/
            Yes, indeed, there is no guarantee for result yet it worked for me in
            the last 5 years or so and never had any corrupt file.
            In our application is a subroutine for a quick backup of a backend
            file (before modifying data). This function was the only solution we
            found for copying an open backend file.
            Of course for a successfull operation one have to be sure there is no
            adding, deleting or modifing data during the copying process.

            Sebastian C.


            Comment

            • David W. Fenton

              #7
              Re: How to copy a mdb file with VBA code

              GrafixSoft@gmai l.com wrote in
              news:0c650a94-952b-404e-82e3-831a48d176e8@k3 0g2000hse.googl egroups.co
              m:
              Yes, indeed, there is no guarantee for result yet it worked for me
              in the last 5 years or so and never had any corrupt file.
              In our application is a subroutine for a quick backup of a backend
              file (before modifying data). This function was the only solution
              we found for copying an open backend file.
              Of course for a successfull operation one have to be sure there is
              no adding, deleting or modifing data during the copying process.
              It will work right up to the point at which it doesn't work.

              I would not consider recommending such a routine to any of my
              clients, since I consider it professional malpractice to gamble with
              my clients' data, which is precisely what you're doing when you do
              something that you are well aware can fail in some percentage of
              cases.

              --
              David W. Fenton http://www.dfenton.com/
              usenet at dfenton dot com http://www.dfenton.com/DFA/

              Comment

              • Tony Toews [MVP]

                #8
                Re: How to copy a mdb file with VBA code

                "Simon van Beek" <SvanBeekNL@Ver satel.nlwrote:
                >How can I make a copy from a database which is in use.
                Why can't you wait until the MDB is no longer in use? If things are that critical
                I'd suggest using SQL Server or other database software with similar 24x7
                capabilities.

                Tony
                --
                Tony Toews, Microsoft Access MVP
                Please respond only in the newsgroups so that others can
                read the entire thread of messages.
                Microsoft Access Links, Hints, Tips & Accounting Systems at

                Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

                Comment

                Working...