Here is example that adds a new record to a table, using two fields: Private Sub cmdCreateTable_Click() Dim curDatabase As Object Dim tblStudents As Object Dim fldFirstName As Object, fldLastName As Object ' Get a reference to the current database Set curDatabase = CurrentDb ' Create a new table named Students Set tblStudents = curDatabase.CreateTableDef("Students") Set fldFirstName = tblStudents.CreateField("FirstName", dbText) tblStudents.Fields.Append fldFirstName Set fldLastName = tblStudents.CreateField("LastName", dbText) tblStudents.Fields.Append fldLastName ' Add the Students table to the current database curDatabase.TableDefs.Append tblStudents End Sub Private Sub cmdDataEntry_Click() Dim curDatabase As Object Dim rstStudents As Object Set curDatabase = CurrentDb Set rstStudents = curDatabase.OpenRecordset("Students") rstStudents.AddNew rstStudents("FirstName").Value = "Helene" rstStudents("LastName").Value = "Mukoko" rstStudents.Update Set rstStudents = Nothing Set curDatabase = Nothing End Sub Here is an example that adds a Boolean value: Private Sub cmdCreateTable_Click() Dim curDatabase As Object Dim tblEmployees As Object Dim colFullName As Object Dim colIsMarried As Object Set curDatabase = CurrentDb Set tblEmployees = curDatabase.CreateTableDef("Employees") Set colFullName = tblEmployees.CreateField("FullName", dbText) tblEmployees.Fields.Append colFullName Set colIsMarried = tblEmployees.CreateField("IsMarried", dbBoolean) tblEmployees.Fields.Append colIsMarried ' Add the Students table to the current database curDatabase.TableDefs.Append tblEmployees End Sub Private Sub cmdCreateRecord_Click() Dim curDatabase As Object Dim rstStudents As Object Set curDatabase = CurrentDb Set rstStudents = curDatabase.OpenRecordset("Employees") rstStudents.AddNew rstStudents("FullName").Value = "Patricia Katts" rstStudents("IsMarried").Value = True rstStudents.Update Set rstStudents = Nothing Set curDatabase = Nothing End Sub
|
|
|
|