Sub ConnectOutput(dbstemp As Database, _
strTable As String, strConnect As String, _
strSourceTable As String)
Dim tdfLinked As Object 'TableDef
Dim rstLinked As Object 'Recordset不行
Dim intTemp As Integer
' Create a new TableDef, set its Connect and
' SourceTableName properties based on the passed
' arguments, and append it to the TableDefs collection.
Set tdfLinked = dbstemp.CreateTableDef(strTable)
tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
MsgBox tdfLinked.Connect & "\" & tdfLinked.SourceTableName
dbstemp.TableDefs.Append tdfLinked '4 有问题
Set rstLinked = dbstemp.OpenRecordset(strTable)
'Set rstLinked = dbsTemp.OpenRecordset(strSourceTable)
Debug.Print "Data from linked table:"
' Display the first three records of the linked table.
intTemp = 1
With rstLinked
Do While Not .EOF And intTemp <= 3
Debug.Print , .Fields(0), .Fields(1)
intTemp = intTemp + 1
.MoveNext
Loop
If Not .EOF Then Debug.Print , "[additional records]"
.Close
End With
'Delete the linked table because this is a demonstration.
dbstemp.TableDefs.Delete strTable
End Sub
Private Sub 命令11_Click()
Dim dbstemp As Database
Dim tablename0 As String
Set dbstemp = OpenDatabase("C:\Documents and Settings\Administrator\桌面\赵工保留\新建文件夹 (6)\db10.mdb")
databaseconnect = "C:\Documents and Settings\Administrator\桌面\daoSTUDY\vba.xls"
tablename0 = "hello"
ConnectOutput dbstemp, _
"ExcelTable", _
[B]" Excel 5.0;" & _[/B]
"DATABASE" = databaseconnect, _
tablename0
[此贴子已经被作者于2003-5-4 20:46:58编辑过]
|