VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Convert rs to HTML or CSV in 2 lines of code

by Mike G (7 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 22nd August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Convert rs to HTML or CSV in 2 lines of code

Rate Convert rs to HTML or CSV in 2 lines of code



' ------------------------------------------------------------
'  Copyright ©2001 Mike G --> IvbNET.COM
'  All Rights Reserved, http://www.ivbnet.com
'  EMAIL : [email protected]
' ------------------------------------------------------------
'  You are free to use this code within your own applications,
'  but you are forbidden from selling or distributing this
'  source code without prior written consent.
' ------------------------------------------------------------


     'Convert rs to comma seperated
Public Function To_CSV(rs As ADODB.Recordset) As String
      To_CSV = rs.GetString(adClipString, -1, ",", vbCrLf, "(NULL)")
End Function

     'Convert rs to HTML table
Public Function To_HTML(rs As ADODB.Recordset) As String
      To_HTML = rs.GetString(adClipString, -1, "</TD><TD>", _
                  "</TD></TR>" & vbCrLf & "<TR><TD>", "(NULL)")
      To_HTML = "<TR><TD>" & Left(To_HTML, Len(To_HTML) - 8)
      To_HTML = "<TABLE> " & To_HTML & "</TABLE>"
End Function

Private Sub cmdcsv_Click()
      Dim sStr As String
      Dim rs As New ADODB.Recordset
      rs.Open "SELECT au_fname,au_lname FROM Authors", "DSN=Pubs"
      sStr = To_CSV(rs)

      Open "D:\test.csv" For Output As #1
      Print #1, sStr
      Close #1
      Set rs = Nothing
      Me.txtFile.LoadFile ("D:\test.csv")
End Sub

Private Sub cmdExit_Click()
      Unload Me
End Sub

Private Sub cmdHTML_Click()
      Dim sStr As String
      Dim rs As New ADODB.Recordset
      rs.Open "SELECT au_fname,au_lname FROM Authors", "DSN=Pubs"
      sStr = To_HTML(rs)

      Open "D:\test.html" For Output As #1
      Print #1, sStr
      Close #1
      Set rs = Nothing
      Me.txtFile.LoadFile ("D:\test.html")
End Sub

Download this snippet    Add to My Saved Code

Convert rs to HTML or CSV in 2 lines of code Comments

No comments have been posted about Convert rs to HTML or CSV in 2 lines of code. Why not be the first to post a comment about Convert rs to HTML or CSV in 2 lines of code.

Post your comment

Subject:
Message:
0/1000 characters