Add a new column to a dao.recordset

L

liz

I want to add a new column/field to a recordset but am not sure of the syntax.

Dim fld as dao.field
Dim rst as dao.recordset

set rst = Set rst = dbs.OpenRecordset("tblName", dbOpenDynaset)
Set fld = New Field
fld.Name = strName

rst.Fields.Append fld *******

*****am getting a run time error here (3272) - method not applicable for
this object.

any suggestions of how to go about it?
 
D

Douglas J. Steele

I don't believe it's possible. Given that DAO recordsets can't be
disconnected, I'm not sure it really makes sense to be able to do it. What
exactly are you trying to do?
 
L

liz

am reading in xml files into access 2000. most of the time the data matches
but occassionally there is the odd one that doesnt so i have written a loop
to check if the column exists - if it doesnt i need to add it to the table.

am writting it as a seperate function now & passing it the table name.
opening the table to check if the column exists
if it does then great
otherwise need to add it to the table

the issue is that i need dao.recordset so can use .fields to check that data
exists.

could i use a docmd.runsql "sqlstring" to add a new field???
just not sure where to start with it?!


--
thanks for you help
liz


Douglas J. Steele said:
I don't believe it's possible. Given that DAO recordsets can't be
disconnected, I'm not sure it really makes sense to be able to do it. What
exactly are you trying to do?
 
D

Douglas J. Steele

As I tried to imply, I don't believe there's any way to add a field to a DAO
recordset, regardless of how you try to do it.

You'll have to add the field to table, not the Recordset.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


liz said:
am reading in xml files into access 2000. most of the time the data
matches
but occassionally there is the odd one that doesnt so i have written a
loop
to check if the column exists - if it doesnt i need to add it to the
table.

am writting it as a seperate function now & passing it the table name.
opening the table to check if the column exists
if it does then great
otherwise need to add it to the table

the issue is that i need dao.recordset so can use .fields to check that
data
exists.

could i use a docmd.runsql "sqlstring" to add a new field???
just not sure where to start with it?!
 
K

Klatuu

Doug is correct. You cannot make schema changes to a recordset. You can
modify the schema of a table using either DAO methods or Jet SQL, but you
can't do that if any user has to table open.
--
Dave Hargis, Microsoft Access MVP


liz said:
am reading in xml files into access 2000. most of the time the data matches
but occassionally there is the odd one that doesnt so i have written a loop
to check if the column exists - if it doesnt i need to add it to the table.

am writting it as a seperate function now & passing it the table name.
opening the table to check if the column exists
if it does then great
otherwise need to add it to the table

the issue is that i need dao.recordset so can use .fields to check that data
exists.

could i use a docmd.runsql "sqlstring" to add a new field???
just not sure where to start with it?!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top