Compact & Repair

Can you please post your entire code and show us which line is highlighted when you get the Bad File name error?
This is the code...
Code:
Private Sub CmdCompactBE_Click()
'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
  
'Link of my BE file
    strTableName = "D:\POS\Purchase Order- V6_be.accdb"        'name of your linked table
'Link of my backup Folder Path
    strFileName = "D:\POS\Data File\BackUp" '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 & " (" & Format(Now, "yyyymmddhhnnss") & ").accdb"
'Link my Backup File Destination
    strDestination = "D:\POS\Data File\BackUp" & " (" & Format(Now, "ddmmyyyyhhnnss") & ").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
 
'Link of my BE file
strTableName = "D:\POS\Purchase Order- V6_be.accdb" 'name of your linked table
This doesn't look like what you said earlier. It should be something like:
Code:
strTableName = "tblOrders"
You also didn't specify which line gets highlighted when you get the error message.
 
theDBguy Error is : 3265 - Item not found in this collection.

I just asking you that #Post_20 & #Post_24 are okay. have there any mistakes?
 
theDBguy Error is : 3265 - Item not found in this collection.

I just asking you that #Post_20 & #Post_24 are okay. have there any mistakes?
Sorry, that doesn't help me help you. I asked you to tell us which line is highlighted when you get the error message. And no, posts #20 and #24 are not okay.

Are you able to post a sample copy of your db (both FE and BE)? You can empty out the tables, if you don't want us to see the data.
 
theDBguy Error is : 3265 - Item not found in this collection.

I just asking you that #Post_20 & #Post_24 are okay. have there any mistakes?
show us which line is highlighted when you get the Bad File name error?
Please try and follow the most basic questions you are being asked. :( That way people can help you much better and a lot quicker?
 
Hi. Thanks for posting a sample db. I modified the code, but I couldn't test it, because we don't have the same file structure. My D drive is a DVD. So, take the attached file and test it, then let us know if you run into any errors.
 

Attachments

Hi. Thanks for posting a sample db. I modified the code, but I couldn't test it, because we don't have the same file structure. My D drive is a DVD. So, take the attached file and test it, then let us know if you run into any errors.
Thanks for your reply. Now Its works with backup file. But my question was C&R in my main file that name is "Purchase Order- V6_be" and Inside table "tblOrder" & "tblPurchase" than take backup.
  1. Can possible to do C&R with main file ?
  2. Can possible to take C&R multiple tables ?
for multiple file I tried it:
Code:
'Link of my BE file
    strTableName1 = "tblOrder"            'name of your linked table
    strTableName2 = "tblPurchase"        'name of your linked table
I tried it for the Source ?
Code:
'Get the source of your back end
    strSource = Split(Split(CurrentDb.TableDefs(strTableName).Connect, "Database=")(1), ";")(0)
REPLACE it
Code:
'Get the source of your back end
    strSource = Split(Split(CurrentDb.TableDefs(strTableName1 & strTableName2).Connect, "Database=")(1), ";")(0)
Its give error same before.
 

Users who are viewing this thread

Back
Top Bottom