Click to See Complete Forum and Search --> : Save Contents in MSFlexgrid


ant
June 20th, 2001, 02:21 PM
What's the code for saving the contents of an MSFlexgrid control????


--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: cgeorge@thevortex.com
for the address

Ghost308
June 20th, 2001, 02:31 PM
If someone can come up with a more sensible solution than this, I'd really really love to read it...

Best way I know of to save the data in a Flexgrid is just to send it all to a text file. Write a Sub in a standard module that will export the data and write one that can load the data.

To save it all, it would probably be best to use a nested for..next loop.

For X = 1 to Flexgrid.Rows
For Y = 1 to Flexgrid.Cols
Buffer = Buffer & Flexgrid.Textmatrix(X,Y) & vbTab
Next Y

Buffer = Buffer & vbCrLf

Next X

...or something of that nature.

ant
June 20th, 2001, 03:13 PM
ok, i got the load and save subs, but where would i put the for loop?

--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: cgeorge@thevortex.com
for the address

Ghost308
June 20th, 2001, 03:18 PM
Inside your save sub, create a string (i called it Buffer in my example) and then use that loop structure to create a big huge string that has all the rows on separate lines (thanks to the "Buffer = Buffer & vbCrLf" line) and it will have all the columbs tabbed (vbTab).

Then you'll need some code to put the buffer in a file; I would use the CommonDialog control and use the .ShowSave method to allow the user to choose where to save the file.

CommonDialog1.ShowSave
Open CommonDialog1.Filename for Output As #1
Print #1, Buffer
Close #1

Does that help some? :)

ant
June 20th, 2001, 05:25 PM
it helped. now i gotta put it all together.............

--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: cgeorge@thevortex.com
for the address

Iouri
June 21st, 2001, 07:41 AM
Why do you want to save MSFlexGrid?. If you want tosave the content on the disk in order to download it later, I think it is a good solution to create a recordset from the flexgrid and save it as xml file

Rst1.Save "c:\Temp\Recordset.xml", adPersistXML

Later you can download from the file to the recordset and restore the flexgrid.
Another advantage of this method is that it will save not only data but also a structure. For example you can save a content of MSHFlexGrid and retrieve the structure later.

Iouri Boutchkine
iouri@hotsheet.com