vb批量修改access数据库

公司给个任务,在某个路径下,所有.abc为后缀文件名为ACCESS数据库的文件,默认有一行hello的用户的记录,密码是123123123,批量把这行记录拿掉。
记录一下,以后省得再弄,不太懂vb弄了个灰头土脸,再回头看看以前那公司的所谓的维护网管,真不懂他们能“维护”什么东西,无论是windows还是linux在我看来。

  1. Dim objFSO
  2. Dim ofolder
  3. Dim objStream
  4. Dim strSearch
  5. Dim strfolderSearch
  6. Set objFSO = CreateObject("scripting.filesystemobject")
  7. Set objStream = objFSO.createtextfile("c:\resolved.txt", True)
  8. strfolderSearch = "E:\wwwroot"
  9. strSearch = ".abc"
  10. strLen=Len(strSearch)
  11. CheckFolder (objFSO.getfolder(strfolderSearch)), objStream
  12. MsgBox "File Search Completed." + vbCr + "Please check c:\resolved.txt for details."
  13. Sub CheckFolder(objCurrentFolder, objtxtFile)
  14.         On Error Resume Next
  15.     Dim strTemp
  16.     Dim strOutput
  17.     Dim objNewFolder
  18.     Dim objFile
  19.     Dim objStream
  20.     For Each objFile In objCurrentFolder.Files
  21.         strTemp = Right(objFile.Name, strLen)
  22.     If UCase(strTemp) = UCase(strSearch) Then
  23.         objtxtFile.writeline CStr(objFile.Path)   
  24.         Dim Conn,SQL
  25.         Dim dbPath,Password
  26.         Set conn = CreateObject("ADODB.Connection")
  27.         dbPath=objFile.Path
  28.         Password="123123123"
  29.         Conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&dbPath&";User ID="&param_dbUserID&";Password="&Password
  30.         If Err Then
  31.             objtxtFile.writeline CStr(objFile.Path) + "-----------" + err.tostring"----------Failed !" 
  32.             Err.CLEAR
  33.             Set Conn = NOTHING           
  34.         Else
  35.             Set RS = Conn.Execute("Select * From admin Where name='hello'")
  36.             If RS.recordcount > 0 Then 
  37.                 Conn.Execute("Delete From admin Where name='hello'")
  38.             End If
  39.             Conn.close
  40.         End if
  41.  
  42.     End If
  43.     Next
  44.     For Each objNewFolder In objCurrentFolder.subFolders
  45.         CheckFolder objNewFolder, objtxtFile
  46.     Next
  47. End Sub

4 Comments

  1. 虽然看起来有点模糊不过还是能了解一点!

  2. 呵呵,这个我懂,遍历目录下所有文件,保存文件列表,然后连接文件列别下的access数据库,然后就是执行SQL了,先判断有没有,有的话删除。OK

  3. 网上应该有这样的修改软件

  4. 兄弟的沙发我非常乐意坐!
    问题是,你的文章太专业了,我们都是外行人,看不懂,看来只有看热闹了。
    期待看到一些非专业性的 POSTS 问世。。。