# Re: 建立资料库

Posted by ChenLu on March 02, 1999 at 20:27:28:

In Reply to: 建立资料库 posted by Fred Tsai on March 01, 1999 at 23:42:06:

: 请教一下各位高手
: 我想要用原有的资料库从其中抓取一些栏位然后令存成一个资料库
: 利用Crystal Report来读取新建立的资料库，这样我的报表就能动态的显示
: 资料，现在我有一个问题，就是如何从原有的资料库新建立一个资料库，
: 我不太懂他的语法可不可以帮忙一下

: 先谢谢您的帮忙

试试看
Dim wks As Workspace
Dim dbNew As Database
Dim tdfNew As TableDef
Dim intFldType As Integer
Dim strFldName As String
Dim intSize As Integer
Dim i As Integer
'Your old table
Dim rsOld As Recordset

Set wks = DBEngine.Workspaces(0)
Set dbNew = wks.CreateDatabase("c:\tmp\Test.mdb", dbLangGeneral)
If dbNew Is Nothing Then
Else
Set tdfNew = dbNew.CreateTableDef("NewTable")
End If
strFldName = ""
'pick up your old table fields & append to new table
With rsOld
For i = 0 To .Fields.Count - 1
strFldName = .Fields(i).Name
intFldType = .Fields(i).Type
If intFldType = dbText Then
intSize = .Fields(i).Size
End If
With tdfNew
If intFldType = dbText Then
.Fields.Append .CreateField(strFldName, intFldType, intSize)
Else
.Fields.Append .CreateField(strFldName, intFldType)
End If
End With
Next i
End With
dbNew.TableDefs.Append tdfNew
............................
........................

Follow Ups:

- Re: 建立资料库 ?? Richard 02:18:14 3/03/99 (0)