View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Alternative to writing to a closed spreadsheet

"GS" wrote:

You treat a worksheet same as a database table. Each row is a
record (starting with row2), each col is a datafield (starting with
col1). A1 would be the first fieldname (heading) in your data table
(worksheet). Each record *must have a unique ID* for referencing a
specific record. Thus you would read/write individual fields of a
specific record (or records).

Otherwise, if your worksheet isn't properly contructed as a data
table should be then you have to use range names or addresses to
read/write specific values.


The target spreadsheet does look like a table of data, with rows and
columns. How do I assign a unique ID to cell A1 in the first row or
first record? Do you have a small example of ADO code that shows how
to
change cell A1 in the first row of a closed spreadsheet?

I have been looking at the example ZIP file that you provided, but so
far I'm only successful at reading from a closed workbook or
appending
a new row at the bottom of a closed workbook.


You work with the data same as you would a database table, where the
worksheet IS a database table. Thus the same process for updating the
file after making changes to the data recordset would be the same. I'm
sure the AppsPro sample demonstrates this so I'd have to look through
it. I believe, though, the code syntax examples would be in the
database section since the workbook section only shows how to work with
closed Excel files. Data manipulation is the same as well as updating
the file with changes to the recordset.

In your case you could use the record index to locate a specific record
(row) to edit/modify since the 'unique ID' concept doesn't really serve
much purpose here, but you should specify a fieldname where its *value*
will be unique for the target record being modified. That means A1 is
the 1st field in the recordset, so ref its position in the Fields
collection like this...

rsData.Fields(0).Name = "NewValue"

...perhaps? Note that fields have 'Name's and records have 'value's for
specific fields! Not sure if you can write the Name property and so
perhaps the Value property is what should be used. (My use of ADO is
quite limited and so I rely on the ADO2.6 Programmer's Reference by
David Sussman for help when needed!)


Otherwise, I store data in txt/dat/inf files and used standard VB file
I/O and arrays for processing. This is how I ref individual records in
an array...

A 0-based array contains the headings (fieldnames);

A 1-based array contains records only because fieldnames have their
own array!

The column indexes respectively match in all so finding/accessing
fields isn't a problem.

...and so you should just use the regular ADO syntax to UPDATE which
recordset *values* for the *fields* you want to edit.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion