Andrew Herrmann
Sep 10th, 1999, 12:26 AM
I'm really new to this database stuff (I just started playing with it today). I've created a table with the code below, but I have no idea how to set the values of each field or how to add additional rows into the table. Any help would be appreciated!
Dim wrkDefault As Workspace
Dim dbsNew As Database
Dim tdfNew As TableDef
Dim Index As Integer
Dim TempStr As String
Dim rstMessage As Recordset
Dim fldData As Field
' Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)
' Make sure there isn't already a file with the name of
' the new database.
If Dir("NewDB.mdb") <> "" Then Kill "NewDB.mdb"
' Create a new encrypted database with the specified
' collating order.
Set dbsNew = wrkDefault.CreateDatabase("NewDB.mdb", _
dbLangGeneral & ";pwd=forbidden", dbEncrypt)
Set tdfNew = dbsNew.CreateTableDef("Message Data")
With tdfNew
' Create fields and append them to the new TableDef
' object. This must be done before appending the
' TableDef object to the TableDefs collection of the
' new database.
.Fields.Append .CreateField("OpCpde", dbByte, 1)
.Fields.Append .CreateField("Length", dbByte, 1)
For Index = 1 To 40
TempStr = "DB" & CStr(Index)
.Fields.Append .CreateField(TempStr, dbByte, 1)
Next Index
End With
dbsNew.TableDefs.Append tdfNew
dbsNew.Close
Dim wrkDefault As Workspace
Dim dbsNew As Database
Dim tdfNew As TableDef
Dim Index As Integer
Dim TempStr As String
Dim rstMessage As Recordset
Dim fldData As Field
' Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)
' Make sure there isn't already a file with the name of
' the new database.
If Dir("NewDB.mdb") <> "" Then Kill "NewDB.mdb"
' Create a new encrypted database with the specified
' collating order.
Set dbsNew = wrkDefault.CreateDatabase("NewDB.mdb", _
dbLangGeneral & ";pwd=forbidden", dbEncrypt)
Set tdfNew = dbsNew.CreateTableDef("Message Data")
With tdfNew
' Create fields and append them to the new TableDef
' object. This must be done before appending the
' TableDef object to the TableDefs collection of the
' new database.
.Fields.Append .CreateField("OpCpde", dbByte, 1)
.Fields.Append .CreateField("Length", dbByte, 1)
For Index = 1 To 40
TempStr = "DB" & CStr(Index)
.Fields.Append .CreateField(TempStr, dbByte, 1)
Next Index
End With
dbsNew.TableDefs.Append tdfNew
dbsNew.Close