944,110 Members | Top Members by Rank

Ad:
Jul 14th, 2007
0

VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Expand Post »
Hi everyone,
if you can recall from my previous posting, I had explained that my "spreadshit does not fit into the same page", but I've now unraveled what the other programmer did to accomplish this goal:
looking at the input table to my spreadsheet, he first used "queryDef" to generate a query, then transfered the query output into a recordset (Access file). Because the recordsets are too long to fit into a spreadsheet, causing the spreadsheet to break up into two parts during printing, he used the "char(10) to break up the recordsets forming two lines of data within the same recordset. For example:

Query Table items:
----------------------
firstname Lastname amount oldhours newhours olddate newdate
====== ====== ===== ====== ===== ===== ======
Michael Jackson 100.00 15.00000 20.00000 02/2/07 02/03/07

Recordset output using char(10) to split the recordset into two line:
----------------------------------------------------------------------------
firstname Lastname amount hours date
====== ====== ===== === ======
Michael Jackson 100.00 15.00 02/02/07
--------- -------------- -------- 20.00 02/03/07

As you can see from the above record , the previous one line of reecord is now two lines, but within the same recordset, making it possible to fit the long record into the spreadsheet.

Now, I was using "CopyFromRecordset" function to import my access file into the spreadsheet, but the carriage return does not take effect to split the record into two lines within the same row.

My objective is to programatically populate the spreadsheet making it possible to fit two lines within the same recordset(row) as in the above example.

Thanks for your anticipated input.
tgifgemini
Similar Threads
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007
Jul 14th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Hi,

Open the RecordSet from the query and Populate Access.
Check this Code:
RST>Recordset Open
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim i As Long
  2. i=0
  3. Do While Not RST.EOF
  4. i=i+1
  5. ExelWS.Cells(i, 1).Value = RST(0)
  6. ExelWS.Cells(i, 2).Value = RST(1)
  7. ExelWS.Cells(i, 3).Value = RST(2)
  8. ExelWS.Cells(i, 4).Value = RST(3)
  9. ExelWS.Cells(i, 5).Value = RST(4)
  10. i=i+1
  11. ExelWS.Cells(i, 4).Value = RST(5)
  12. ExelWS.Cells(i, 5).Value = RST(6)
  13. '
  14. RST.MoveNext
  15. Loop


Regards
Veena
Last edited by QVeen72; Jul 14th, 2007 at 6:02 am.
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Jul 15th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Thanks Veena,
I'm gonna give it a go when I get to work tomorrow.
Have a nice weekend.
GiftX.
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007
Jul 17th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Hello Veena,
you gave me these codes to populate a spreadsheet one at a time from a recordset. What happens when you don't know how many cells/rows you need to populate in the spreadsheet? How would you code populating number of cells/rows based on the number of data in the recordset?
Below is the initial code you supplied:
Open the RecordSet from the query and Populate Access.
Check this Code:
RST>Recordset Open

Dim i As Long
i=0
Do While Not RST.EOF
i=i+1
ExelWS.Cells(i, 1).Value = RST(0)
ExelWS.Cells(i, 2).Value = RST(1)
ExelWS.Cells(i, 3).Value = RST(2)
ExelWS.Cells(i, 4).Value = RST(3)
ExelWS.Cells(i, 5).Value = RST(4)
i=i+1
ExelWS.Cells(i, 4).Value = RST(5)
ExelWS.Cells(i, 5).Value = RST(6)
'
RST.MoveNext
Loop

Regards
Veena
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007
Jul 17th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Hi,

The above code works irrespective of Number of records in the Recordset.(up to Max Limit of excel which i think is 64k of rows..not very sure)

as far as columns is considerd, u have to code to break into second line.

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Jul 17th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Good morning Veena,
just a little calarification:
does these codes:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ExelWS.Cells(i, 1).Value = RST(0)
  2. ExelWS.Cells(i, 2).Value = RST(1)
  3. ETC......

is the above code setting up the columns(recordset nodes -
Fname, Lname, age, salary, hours etc.... ?
in otherwords setting up each record?
I am just wondering why I'm hard-coding
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. rs(0) to rs(6)
Thanks
tgifgemini.
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007
Jul 18th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

try to make a variable for y axis by setting it to the number of records of your data to make your code more flexible...
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Jul 18th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Hi tgif,

as i dint know ur Field Names, i wrote rs(0)...etc..

u can use:

ExelWS.Cells(i, 1).Value = RST("FName")
ExelWS.Cells(i, 2).Value = RST("LName")

Replace ur field names.

REgards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Jul 18th, 2007
0

Re: VB6/Excel - Using Char(10) to fit a long rcrdset as two lines within same recordset

Thanks veena and all other contributors to this thread. It's quite clear now. I thought as much that's that objective but I wanted to be sure.
You all have a great week.
tgifgemini.
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Problem
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: apply searching in VB 6.0





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC