 |
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
|
|
|

November 4th, 2005, 08:08 AM
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

November 4th, 2005, 09:32 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

November 4th, 2005, 04:42 PM
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Do you need a reference to some Shell Object or Scripting command in MS Access?
Database Agreements
|

November 7th, 2005, 11:13 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

November 8th, 2005, 05:30 AM
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

November 8th, 2005, 08:38 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

November 11th, 2005, 06:25 AM
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Works perfectly. Thanks very much, you have no idea how much this helps.
Spikey
|

November 11th, 2005, 07:00 AM
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hmm.
I wonder what happens if the .mdb is locked.
Do you get an Error and would you deal with it gracefully?
Database Agreements
|
|
 |