
VB3 appending a field to a table, then entering data into the new field
Quote:
>'**** I create a database to store measurements with the createdatabase command.
>'**** I need a fixed number of tables which i have created.
>'**** I then need to add new fields to a specific table.
>'**** The number of fields will vary from table to table.
>'**** Basically, the database is a simple (not relational) database with
>'**** rows (records) and columns (fields).
>'**** The database is used to store data from and supply data to a grid.
>'**** The sub i have written allows me to append the new field to the table chosen
>Dim measurement As String
>measurement = "20.02"
>Dim field_name As New Field
>Dim table_name As tabledef
>'**** table_1 is an existing table
>Set table_name = my_database.TableDefs("table_ 1")
>'**** add a new field to the correct record
>field_name.Name = "field_2"
>field_name.Type = DB_TEXT
>field_name.Attributes = DB_UPDATABLEFIELD
>field_name.Size = 6
>'**** add a new field
>table_name.Fields.Append field_name
>'**** I now want to enter a string (called measurement) into the new field
>data1.RecordSource = table_name
>'*************************************************************************
>'**** this reports an error
>data1.Database.TableDefs(table_name).Fields(field_name) = measurement
>'**** The error states -> Property value only valid when field is part of a recordset
>'**** My question is - why does this not work!!!
>'**** I think that I need to establish a recordset but the help files
>'**** do not make this clear.
>'**** If this is correct how do I do this.
Dim db as database
Dim dy as dynaset
set db = OpenDatabase("C:\data\mydb.mdb", false, false)
set dy = db.Createdynaset("Select * from table_1")
dy.recordset.Edit
dy.recordset.fields("field_2") = "measurement"
dy.recordset.Update
dy.close
db.close
Check out the Edit method in the on-line help. Be
sure to call Update after an edit.
http://www.xnet.com/~kd9fb