Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2005, 08:08 AM
Authorized User
 
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default Renaming remote mdb file

I have a database which controls the operation of 15 others. At times the remote databases grow too large and need compacting. Rather than doing this manually, I want to programme the master database to firstly compact the remote databases and then repopulate them. One can use Application.CompactRepair to do the first stage, but this demands a new name for the compacted database. I can then use KILL to delete the original database, but I cannot find a way of renaming the compacted database with the original name. Would a Shell command work here? Can anyone suggest another way to do this?

Thanks

 
Old November 4th, 2005, 09:32 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I know you can do this in two steps from Access code. The first is to copy the file with the name you want, and the second is to delete the old file:

'-----
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.CopyFile "C:\YourOldFileName.mdb", "C:\YourNewFileName.mdb", True
objFSO.DeleteFile("C:\YourOldFileName.mdb")
'-----

The "True" boolean is to overwrite an existing file with the same name.

HTH


mmcdonal
 
Old November 4th, 2005, 04:42 PM
Authorized User
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you need a reference to some Shell Object or Scripting command in MS Access?


Database Agreements
 
Old November 7th, 2005, 11:13 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry for the delay:

You will need to declare some items if you have option explicit. I generally do the following and end up with Variants:

Dim WshShell
Dim objFSO

Notice I don't "type" the variables (e.g. "As String," "As Long" etc.)

Otherwise it works with MDAC and WMI. Are you having any problems using this?



mmcdonal
 
Old November 8th, 2005, 05:30 AM
Authorized User
 
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry, but I cannot get this to work. I have tried 'Dim'-ing the variables as either nothing ( = a Variant), directly as a Variant, and even as an Object, but the programme fails to recognise the commands. I have also tried adding the 'Microsoft Script Control 1.0' to my references [the only one that looked even remotely relevant] with no effect. There must be something else I'm missing. Any thoughts?

Thanks for trying


 
Old November 8th, 2005, 08:38 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, slight modification. I got this to work on a button click:

'-----
Private Sub Command0_Click()

Dim objFSO

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.CopyFile "C:\YourOldFileName.mdb", "C:\YourNewFileName.mdb", True
objFSO.DeleteFile ("C:\YourOldFileName.mdb")

End Sub
'-----

HTH

mmcdonal
 
Old November 11th, 2005, 06:25 AM
Authorized User
 
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Works perfectly. Thanks very much, you have no idea how much this helps.

Spikey


 
Old November 11th, 2005, 07:00 AM
Authorized User
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm.
I wonder what happens if the .mdb is locked.
Do you get an Error and would you deal with it gracefully?


Database Agreements





Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming an Email File Attachment jpwalters C# 1 May 21st, 2008 12:43 PM
Renaming File ayazhoda Access VBA 3 April 24th, 2007 05:43 AM
Renaming a file during upload keph Pro PHP 1 October 6th, 2005 07:14 PM
Renaming File During Upload keph Beginning PHP 1 October 4th, 2005 02:46 PM
Error 7399 when accessing REMOTE .mdb VerdaFolio SQL Server 2000 2 July 9th, 2003 01:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.