# Re: 建立资料库 ??

Posted by Richard on March 03, 1999 at 02:18:14:

In Reply to: Re: 建立资料库 posted by ChenLu on March 02, 1999 at 20:27:28:

: : 请教一下各位高手
: : 我想要用原有的资料库从其中抓取一些栏位然后令存成一个资料库
: : 利用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
: ............................
: ........................

But create a tmp database will have a problem of same repeated mdb name in application or many tmp files/waste in hard disk due to accidentally power off.
Could I also ask how can I create a cursor like table in VB?

Follow Ups: