I want to loop in a folder and subfolder to run a compact database script below. How do i do the loop? Below is the hardcoded script. I want to loop and select all *.accdb files and run the script below on them.
Dim objFSO Dim objEngine Dim strLckFile Dim strSrcName Dim strDstName Dim strPassword
strLckFile = "C:Accesswebforumsfoo.laccdb" strSrcName = "C:Accesswebforumsfoo.accdb" strDstName = "C:Accesswebforumscompacted.accdb" strBackup = "C:Accesswebforumsfoobackup.accdb" strPassword = "foo"
Set objEngine = CreateObject("DAO.DBEngine.120")
Set objFSO = CreateObject("Scripting.FileSystemObject") If Not (objFSO.FileExists(strLckFile)) Then If (objFSO.FileExists(strBackup)) Then objFSO.DeleteFile strBackup End If If (objFSO.FileExists(strDstName)) Then objFSO.DeleteFile strDstName End If objFSO.CopyFile strSrcName, strBackup ''dbVersion120 = 128 objEngine.CompactDatabase strSrcName, strDstName, , 128, ";pwd=" & strPassword objFSO.DeleteFile strSrcName objFSO.MoveFile strDstName, strSrcName
End If 'LckFile
loop in a folder
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- abenitez77
- Posts: 8
- Last visit: Fri Dec 23, 2011 2:07 am
loop in a folder
I want to loop in a folder and subfolder to run a compact database script below. How do i do the loop? Below is the hardcoded script. I want to loop and select all *.accdb files and run the script below on them.
Dim objFSO Dim objEngine Dim strLckFile Dim strSrcName Dim strDstName Dim strPassword
strLckFile = "C:Accesswebforumsfoo.laccdb" strSrcName = "C:Accesswebforumsfoo.accdb" strDstName = "C:Accesswebforumscompacted.accdb" strBackup = "C:Accesswebforumsfoobackup.accdb" strPassword = "foo"
Set objEngine = CreateObject("DAO.DBEngine.120")
Set objFSO = CreateObject("Scripting.FileSystemObject") If Not (objFSO.FileExists(strLckFile)) Then If (objFSO.FileExists(strBackup)) Then objFSO.DeleteFile strBackup End If If (objFSO.FileExists(strDstName)) Then objFSO.DeleteFile strDstName End If objFSO.CopyFile strSrcName, strBackup ''dbVersion120 = 128 objEngine.CompactDatabase strSrcName, strDstName, , 128, ";pwd=" & strPassword objFSO.DeleteFile strSrcName objFSO.MoveFile strDstName, strSrcName
End If 'LckFile
Dim objFSO Dim objEngine Dim strLckFile Dim strSrcName Dim strDstName Dim strPassword
strLckFile = "C:Accesswebforumsfoo.laccdb" strSrcName = "C:Accesswebforumsfoo.accdb" strDstName = "C:Accesswebforumscompacted.accdb" strBackup = "C:Accesswebforumsfoobackup.accdb" strPassword = "foo"
Set objEngine = CreateObject("DAO.DBEngine.120")
Set objFSO = CreateObject("Scripting.FileSystemObject") If Not (objFSO.FileExists(strLckFile)) Then If (objFSO.FileExists(strBackup)) Then objFSO.DeleteFile strBackup End If If (objFSO.FileExists(strDstName)) Then objFSO.DeleteFile strDstName End If objFSO.CopyFile strSrcName, strBackup ''dbVersion120 = 128 objEngine.CompactDatabase strSrcName, strDstName, , 128, ";pwd=" & strPassword objFSO.DeleteFile strSrcName objFSO.MoveFile strDstName, strSrcName
End If 'LckFile
loop in a folder
Hi. Here is onform of looping statement in VBscript.
Do [{While | Until} condition] [statements] [Exit Do] [statements]Loop
Another useful method is:
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]And of course you can use a while loop.While condition
[statements]
Wend
Do [{While | Until} condition] [statements] [Exit Do] [statements]Loop
Another useful method is:
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]And of course you can use a while loop.While condition
[statements]
Wend