Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print out entire contents of Record Set 1

Status
Not open for further replies.

milage

Programmer
Jul 13, 2001
58
US
Hi,

Is there a way of churning out all the contents of a record set. I don't know what fields are going to be in it I just want to list everything in a table without having to explicitly put the name of each field as the field names and numbers are likely to change.

 
Milage,

Here is a subroutine that will out put a recordset in table format. Just send the sub your object recordset.

fengshui1998


objrs.fields.count - Tells how many fields

'***************************
Sub Display_Table(rstmp)
'***************************
strAlign = &quot;<TH ALIGN=&quot;&quot;center&quot;&quot;>&quot;
strFont = &quot;<FONT style=&quot;&quot;font-family:Helvetica;color:#FFFFFF;font-size:9pt&quot;&quot;>&quot;
strFont2 = &quot;<FONT style=&quot;&quot;font-family:Arial;font-size:9pt;color:#00008C&quot;&quot;>&quot;
strTD = &quot;<TD NOWRAP ALIGN=&quot;&quot;center&quot;&quot; style=color:#00008c>&quot;

Dim QArray
If Not rstmp.EOF Then
QArray = rstmp.GetRows()

response.write &quot;<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0><TR BGCOLOR=&quot;&quot;#000080&quot;&quot;>&quot;

For I = 0 To UBound(QArray, 1)
response.write strAlign & strFont & &quot;<B>&quot; & _
Trim(rstmp.Fields(I).Name) & &quot;</B></FONT></TH>&quot;
Next

response.write &quot;</TR>&quot;

For I = 0 To UBound(QArray, 2)
Response.Write &quot;<TR BGCOLOR=&quot;&quot;#FFFFFF&quot;&quot;>&quot;

For J = 0 to UBound(QArray, 1)
Value = Trim(QArray(J, I))
If Value = &quot;&quot; or IsNull(value) Then Value = &quot; &quot;
response.write strTD & strfont2 & Value & &quot;</FONT></TD>&quot;
Next
Response.Write &quot;</TR>&quot;
Next

End If
Set rstmp = Nothing
Response.Write &quot;</Table>&quot;
rstmp.Close

End Sub


 
Excellent. Thanks alot.

The only problem was that it didn't like closing the recordset at the end? &quot;Object expected&quot; But once I'd taken that line out it worked fine!

Cheers

Milage

(And that deserves a star!)
 
fengshui1998 that is one handy sub.....:)

To clear up the problem with the rstmp giving an error when closing the order is all that is wrong. You could modify:

Set rstmp = Nothing
Response.Write &quot;</Table>&quot;
rstmp.Close

End Sub

To

rstmp.Close
Set rstmp = Nothing
Response.Write &quot;</Table>&quot;

End Sub


but this guy is forsure going into my folder of useful snippets....thanks fengshui1998!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top