Option Explicit
Dim objWMIService, objProcess, colProcesslist
Dim i%, j%, aa$, bb$, fname$, DriveNm$(), Filestr$(), Trec&, s
Private Sub Command1_Click()
ReDim Preserve Filestr$(0)
Trec = 0: Filestr(0) = ""
fname = "c:\tmpstr.txt"
List1.Clear
If Dir(fname) <> "" Then Kill fname
Me.Caption = "搜索中,请稍侯......!!"
Call Shell("cmd /c dir c:\*.mdb /s/b >" & fname, vbHide)
Do
DoEvents
If Not Isrunexe("cmd.exe") Then Exit Do
Loop
If FileLen(fname) > 0 Then
List1.Visible = False
Open fname For Input As #1
While Not EOF(1)
Line Input #1, aa
ReDim Preserve Filestr$(Trec)
Filestr(Trec) = aa
If InStr(aa, "200") > 0 Then
bb = Getdate(aa)
If bb <> "" Then List1.AddItem bb & "," & Filestr(Trec)
End If
Trec = Trec + 1
Wend
Close #1
List1.Visible = True
For i = 0 To List1.ListCount - 1
aa = List1.List(i)
s = Split(aa, ",")
Filestr(i) = s(1)
Print Filestr(i)
Next i
End If
Me.Caption = "搜索完成!!"
If Trec = 0 Then MsgBox "未搜索到欲查找的文件": Exit Sub
MsgBox "共搜到 " & CStr(Trec) & " 个数据库" & vbCrLf & Chr(10) & "日期命名的有:" & CStr(List1.ListCount) & " 个文件"
End Sub
Public Function Isrunexe(ExeNm As String) As Boolean
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcesslist = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & ExeNm & "'")
Isrunexe = IIf(colProcesslist.Count > 0, True, False)
Set objWMIService = Nothing
Set colProcesslist = Nothing
End Function
Function Getdate(Tstr$) As String
Getdate = ""
j = InStrRev(Tstr, "\")
If j > 0 Then
Tstr = Mid(Tstr, j + 1)
Tstr = Replace(Tstr, "-", "")
j = InStr(Tstr, ".")
If j > 0 Then
Tstr = Mid(Tstr, 1, j - 1)
If Len(Tstr) < 6 Then Tstr = Mid(Tstr, 1, 4) & "0" & Mid(Tstr, 5, 1)
Getdate = Tstr
End If
End If
End Function
strFile = Dir("C:\PROG\BACKUP\*.MDB")
Do Until strFile = ""
Combo1.AddItem strFile
Loop
If Combo1.ListCount Then Combo1.ListIndex = 0
strFie = Dir("C:\PROG\*.MDB")
If strFile > "" Then
Combo1.AddItem strFile
Combo1.ItemData(Combo1.NewIndex) = 1
ADODC1.DatabaseName = "C:\PROG\" & strFile
ADODC1.RecordSource = "SELECT * FROM 你的表名称"
Set DataGrid1.DataSource = ADODC1
DataGrid1.Refresh
End If
Command1.Caption = "查看记录(&V)"
End Sub
Private Sub Command1_Click()
Dim strPathFile As String
strPathFile = "C:\PROG\" & IIf(Combo1.ItemData(Combo1.ListIndex), "", "BACKUP\") & Combo1.List(Combo1.ListIndex)
If Dir(strPathFile) > "" Then
ADODC1.DatabaseName = strPathFile
ADODC1.RecordSource = "SELECT * FROM 你的表名称"
Set DataGrid1.DataSource = ADODC1
DataGrid1.Refresh
End If
End Sub
sub COMMAND1_click()
CommonDialog1.ShowOpen
mymdb=CommonDialog1.FileName
strConn = "Driver={Microsoft Access Driver(*.mdb)};DBQ=" & mymdb & ";"
Set curConnection = New ADODB.Connection
Set rs = New ADODB.Recordset
curConnection.Provider = "Microsoft.Jet.OLEDB.4.0" '3.51"
curConnection.Open strConn
If curConnection.State = adStateOpen Then
strSQL = "select * from mytable"
rs.Open strSQL, curConnection, adOpenStatic, adLockReadOnly
DATAGRID.datesource=rs
end if
end sub