Results 1 to 11 of 11
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097

    Error renaming a backend DB

    I have a new general module that needs to relink to a temporary backend so as to free up the current backend making it available for renaming. Module heading explains the whole purpose. Anyway, I get an error when trying to rename. I thought relinking to a temporary DB would free up the current, but perhaps further action is required? I don't see an explicit DoCmd to close just a backend DB?


    Code:
    Public Sub RevertDB(strCurDB As String, strTempDB As String, frmClose As String, BkUpDB As String)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  07/16/2024
    '  Revert current backend to a previous level from "Round Robin" backup collection.
    '  Close invoking form, re-link backend to a temporary DB (usually the sandbox DB),
    '  rename the current client's DB so as to preserve it, replace the backend DB from
    '  the backups collection and re-link.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim strPreservedDB As String
    Dim strAction
    Dim FSO As Object
    
    
    'On Error GoTo RevertErr
    
    
    DoCmd.Close acForm, frmClose         'Close the invoking form
    
    
    Call ReLink(strTempDB, True)
    
    
    strPreservedDB = Replace(strCurDB, "Data.mdb", "Data(Preserved).mdb")
    strAction = "renaming"
    Name strCurDB As strPreservedDB
    
    
    
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.CopyFile BkUpDB, strCurDB
    Set FSO = Nothing
    
    
    Call ReLink(strCurDB, True)
    
    
    ExitSub: Exit Sub
    
    
    RevertErr:
    MsgBox "Error " & Err.Number & " while attempting to " & strAction & " DB" & vbNewLine & _
           "Description is " & Err.Description
    GoTo ExitSub
           
    End Sub
    
    I suppressed the error handler so I could get the following screenshots
    
    Click image for larger version. 
    
    Name:	000.jpg 
    Views:	20 
    Size:	73.3 KB 
    ID:	52001
    Click image for larger version. 
    
    Name:	001.jpg 
    Views:	20 
    Size:	17.3 KB 
    ID:	52002
    Click image for larger version. 
    
    Name:	002.jpg 
    Views:	20 
    Size:	19.4 KB 
    ID:	52003

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Was the backend DB opened/locked by the front end when you tried it?

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    You're trying to rename a be when it is still open? Just because you unlink from it doesn't mean it closes. You cannot use Name statement on an open file. Did you debug the variables to ensure the paths were valid? Did you copy the output (at least up to the last folder) and try pasting it into a File Explore dialog to be sure?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Closing the backend was, I thought, the focus of my OP. I looked for some form of DoCmd.Close acdatabase, MyBackend but only found what amounted to a DoCmd.Quit. If there's a way to close the backend I'd sure like to know how to do that.

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    try

    Dim OtherDB As Object
    Set OtherDB = GetObject("C:\etc\etc\etc.SomeOtherDb.accdb") 'or mdb?
    OtherDB.Application.Quit

    I have to assume that code won't be in the db you're trying to close, otherwise you'd use Quit as you say. It doesn't test if the db is actually open. No idea what the error number would be if it was not.
    Last edited by Micron; 07-16-2024 at 08:03 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Are you trying to back up the backend?

    https://www.accessmvp.com/thedbguy/c...p?title=backup
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    BUMMER! Same error.
    Code:
    snip
    
    Dim ClientDB As Object
    'On Error GoTo RevertErr
    
    
    DoCmd.Close acForm, frmClose         'Close the invoking form
    
    
    Call ReLink(strTempDB, True)
    
    
    strPreservedDB = Replace(strCurDB, "Data.mdb", "Data(Preserved).mdb")
    strAction = "renaming"
    
    
    
    
    Set ClientDB = GetObject(strCurDB)
    ClientDB.Application.Quit
    Name strCurDB As strPreservedDB          <<<<<<<<<<<<
    
    Snip

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    At this point I can only point you back to questions 2 and 3 in my first post. If I was sure about that, I would open an unrelated be or even an unsplit db and try that code on it.
    Also https://learn.microsoft.com/en-us/of...error-error-75
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    So that I don't waste anyone else time, I think I know how to solve this issue using an operating system technique. I'll post back with the solution after I prove myself right about the idea.

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Just some slight changes to Brent's code will do what you want.
    I added arguments for the table, backend name and backend file extension.


    Code:
    Public Sub BackUpAndCompactBE(vTable As String, BEName As String, FType As String)
    
    'vTable is the name of a table in your backend
    'BEName is the name for the saved backend
    'FType is the file type of the backend ie. Accdb or Mdb
    
    'Courtesy of Brent Spaulding (datAdrenaline), MVP
    'Modified by theDBguy on 5/27/2019
    'Source: http://www.accessmvp.com/thedbguy
    
    
    On Error GoTo errHandler
    
    
        Dim oFSO As Object
        Dim strDestination As String
        Dim strSource As String
        Dim strTableName As String
        Dim strFileName As String
    
    
        strTableName = vTable  'name of your linked table
        strFileName = "\" & BEName      'name of your backup file
    
    
        'Get the source of your back end
        strSource = Split(Split(CurrentDb.TableDefs(strTableName).Connect, _
                "Database=")(1), ";")(0)
        
        'Determine your destination
        strDestination = CurrentProject.Path & strFileName & "." & FType '" (" _
               ' & Format(Now, "yyyymmddhhnnss") & ").accdb"
        
        'Flush the cache of the current database
        DBEngine.Idle
        
        'Create a file scripting object that will backup the db
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        oFSO.CopyFile strSource, strDestination
        Set oFSO = Nothing
        
        'Compact the new file, ...
        Name strDestination As strDestination & ".cpk"
        DBEngine.CompactDatabase strDestination & ".cpk", strDestination
        'Uncomment the following line and comment the previous line
        'if your backend file is password protected or if you want the backup to have a password
        'DBEngine.CompactDatabase strDestination & ".cpk", strDestination, , , ";pwd=YourPassword"
        Kill strDestination & ".cpk"
        
        'Notify users
        MsgBox "Backup file '" & strDestination & "' has been created.", _
                vbInformation, "Backup Completed!"
        
    errExit:
        Exit Sub
        
    errHandler:
        MsgBox Err.Number & ": " & Err.Description
        Resume errExit
        
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Okay, the app at issue supports multiple clients, (one BE DB per client). When the app starts-up, the app interrogates the command string in search of the client name so that the appropriate BE tables be linked. Thus, no BEs are opened until that operation is completed. I've implemented a command stack in the app's front-end that will get serviced before anything else is done. The client UI, for backup restores, now simply puts the "Revert" command on the stack together with the name of the requested backup DB and the client user is instructed to restart the app before the app quits itself. With this approach, none of the conflicts due to an open BE are encountered. Another advantage of this approach is the simple addition of a undo command being placed on the stack. The "Revert" command processor is included here below.

    Thanks to all that gave this OP their valuable time,
    Bill

    Code:
    Public Sub RevertDB(strClient As String, strBkUpDB As String)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  07/16/2024 - "Revert" command processing
    '  Followinbg a "preserve" renaming of the clients BE DB, revert to a backend copy
    '  the client revert UI choose from the "Round Robin" backup collection.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim strAction
    Dim FSO As Object
    Dim strClientDB As String
    Dim strPreservedDB As String
    
    
    On Error GoTo RevertErr
    
    
    strClientDB = TMSRoot & "TMS-Clients\" & strClient & "\" & strClient & " DATA.mdb"
    
    
    strPreservedDB = Replace(strClientDB, "Data.mdb", "Data(Preserved).mdb")
    strAction = "rename"
    Name strClientDB As strPreservedDB
    
    
    strAction = "restore BE"
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.CopyFile strBkUpDB, strClientDB
    Set FSO = Nothing
    
    
    ExitSub: Exit Sub
    
    
    RevertErr:
    MsgBox "Error " & Err.Number & " while attempting to " & strAction & " DB" & vbNewLine & _
           "Description is " & Err.Description
    GoTo ExitSub
           
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error Message After renaming Database
    By 190confed in forum Access
    Replies: 12
    Last Post: 11-15-2018, 07:53 PM
  2. Renaming database causes missing reference error
    By Banjani in forum Programming
    Replies: 2
    Last Post: 12-19-2016, 03:02 PM
  3. error 3027 on backend file
    By vicsaccess in forum Access
    Replies: 3
    Last Post: 06-09-2016, 11:13 AM
  4. Error linking to an access backend on a different computer
    By amd711 in forum Import/Export Data
    Replies: 6
    Last Post: 02-25-2013, 09:48 AM
  5. Replies: 7
    Last Post: 08-27-2012, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums