VB3 appending a field to a table, then entering data into the new field 
Author Message
 VB3 appending a field to a table, then entering data into the new field

'**** 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.



Thu, 14 Jan 1999 03:00:00 GMT  
 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



Fri, 15 Jan 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB3 entering data to a newly appended field

2. Create new fields in a table based off of fields in another table

3. Create new field in existing table exactly like field in second table

4. Append new fields into Table ?

5. entering data from set of same fields to different rows in a table

6. How to modified existing field and add new field in existing table for Access database

7. Some fields in my table does not store the new data but only NULL

8. VB3 - using append to add fields problem

9. Append memo field to a different memo field

10. updating fields in table from field in another table

11. Using ENTER key to move from field to field

12. Fill field in one table from field in another table

 

 
Powered by phpBB® Forum Software