|
谁能将以下代码改为ado的形式呢?不胜感激。。。
Public Function GetTableNames(Optional Attrib As Long = 0) As String
'»ñÈ¡µ±Ç°Êý¾Ý¿âËùÓбíµÄÃû³Æ
'Attrib: dbSystemObject
Dim str As String
Dim i As Integer
For i = 0 To CurrentDb.TableDefs.Count - 1
If Attrib <> 0 Then
If (CurrentDb.TableDefs(i).Attributes And Attrib) Then
str = str & CurrentDb.TableDefs(i).Name & ";"
End If
Else
If (CurrentDb.TableDefs(i).Attributes = Attrib) Then
str = str & CurrentDb.TableDefs(i).Name & ";"
End If
End If
Next i
GetTableNames = str
End Function
Public Function GetQueryNames(Optional QueryDefTyp As Integer = dbQSelect) As String
Dim str As String
Dim i As Integer
For i = 0 To CurrentDb.QueryDefs.Count - 1
If CurrentDb.QueryDefs(i).Type = QueryDefTyp Then
str = str & CurrentDb.QueryDefs(i).Name & ";"
End If
Next i
GetQueryNames = str
End Function
Public Function GetFieldNames(TableQueryName As String, blTable As Boolean) As Words
Dim i As Integer
Dim FieldNames As New Words
Dim MyObject As Object
If blTable Then
Set MyObject = CurrentDb.TableDefs(TableQueryName).Fields ' ´´½¨Ò»¸öÕýÈ·µÄ¶ÔÏóÒýÓá£
For i = 0 To MyObject.Count - 1
FieldNames.Add CurrentDb.TableDefs(TableQueryName).Fields(i).Name, CurrentDb.TableDefs(TableQueryName).Fields(i).Name
Next i
Else
Set MyObject = CurrentDb.QueryDefs(TableQueryName).Fields ' ´´½¨Ò»¸öÕýÈ·µÄ¶ÔÏóÒýÓá£
For i = 0 To MyObject.Count - 1
FieldNames.Add CurrentDb.QueryDefs(TableQueryName).Fields(i).Name, CurrentDb.QueryDefs(TableQueryName).Fields(i).Name
Next i
End If
Set GetFieldNames = FieldNames
End Function
Public Sub GetTableName(DataName As String)
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
CurrentDb.Execute "delete from RepTable"
Set dbs = OpenDatabase(DataName)
Set rs = dbs.OpenRecordset("SELECT [msysobjects].[Name], [Type]=1 AS IsTable " _
& "FROM msysobjects " _
& "WHERE ((([msysobjects].[Type])=5 Or ([msysobjects].[Type])=1) " _
& "And ((Left([name],4))<>'MSys') And ((Left([name],1))<>'~')) " _
& "ORDER BY [msysobjects].[Type], [msysobjects].[Name]; ")
Do Until rs.EOF
CurrentDb.Execute "insert into RepTable ([Name],[Table]) values ('" & rs.Fields(0) & "'," & BoolToStr(rs.Fields(1)) & ")"
rs.MoveNext
Loop
End Sub
Private Function BoolToStr(bl As Boolean) As String
If bl Then
BoolToStr = "yes"
Else
BoolToStr = "no"
End If
End Function
Public Sub cc()
DoCmd.TransferDatabase acExport, "Microsoft Access", "d:\accxp\±¨±í×Ô¶¯Éú³É\Northwind.mdb", acReport, "±¨±í1111", "Rep2k"
End Sub
|
|