Results 1 to 3 of 3

Thread: Export Help

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Export Help

    Hi!

    I Created a report with Data environment... It is displayed on the screen. How can I dynamically export the results into an html file from within VB...

    Thanks in advance for any help Or ideas...

  2. #2
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Here is an example how it could be done.
    VB Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    2.  
    3. Private Sub Command1_Click()
    4.     CreateHTMLReport "SELECT * FROM Users", "D:\Databases\db.mdb", "C:\Output.html", "USERS LISTING", True
    5. End Sub
    6.  
    7. Private Sub CreateHTMLReport(SQL As String, _
    8.                             DBPath As String, _
    9.                             ReportFile As String, _
    10.                             ReportTitle As String, _
    11.                             Optional OpenReport As Boolean = True)
    12.                            
    13. Dim rs, connect, fso, fso_file, fso_ts, line_color
    14.  
    15.     SQL = "SELECT * FROM Users" 'your SQL statement
    16.     connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath
    17.    
    18.     Set rs = CreateObject("ADODB.Recordset")
    19.     rs.Open SQL, connect
    20.    
    21.     If Not rs.EOF Then
    22.         Set fso = CreateObject("Scripting.FileSystemObject")
    23.         fso.CreateTextFile (ReportFile)
    24.         Set fso_file = fso.GetFile(ReportFile)
    25.         Set fso_ts = fso_file.OpenAsTextStream(2)
    26.        
    27.         With fso_ts
    28.             .write ("<HTML>")
    29.             .write ("<HEAD>")
    30.             .write ("<TITLE>" & ReportTitle & "</TITLE>")
    31.             .write ("</HEAD>")
    32.             .write ("<BODY>")
    33.             .write ("<DIV ALIGN='center'>")
    34.             .write ("<H2>" & ReportTitle & "</H2>")
    35.             .write ("<SPAN STYLE='font-family:Tahoma;font-size:11px'>|&nbsp;<A HREF='javascript:window.print()'>PRINT REPORT</A>&nbsp;|&nbsp;<A HREF='javascript:window.close()'>CLOSE WINDOW</A>&nbsp;|</SPAN><BR><BR>")
    36.             .write ("<TABLE BORDERCOLOR='#C0C0C0' WIDTH='95%' STYLE='border-collapse:collapse;font-family:Arial;font-size:12px' BORDER='1'>")
    37.             .write ("<TR BGCOLOR='#000000'>")
    38.            
    39.             For i = 0 To rs.fields.Count - 1
    40.                 .write ("<TH NOWRAP STYLE='color:#FFFFFF' ALIGN='center'><B>&nbsp;" & rs(i).Name & "&nbsp;</B></TH>")
    41.             Next i
    42.            
    43.             .write ("</TR>")
    44.            
    45.             Do Until rs.EOF
    46.                 If line_color = "#E8E8E8" Then line_color = "#F4F4F4" Else: line_color = "#E8E8E8"
    47.                 .write ("<TR BGCOLOR='" & line_color & "'>")
    48.                 For i = 0 To rs.fields.Count - 1
    49.                     .write ("<TD ALIGN='left'>&nbsp;" & rs(i) & "</TD>")
    50.                 Next i
    51.                 .write ("</TR>")
    52.                 rs.movenext
    53.             Loop
    54.            
    55.             .write ("<TR>")
    56.             .write ("<TD ALIGN='center' STYLE='font-family:Arial;font-size:10px' COLSPAN='" & rs.fields.Count & "'>Printed: " & Format(Now(), "mmmm dd, yyyy hh:mm ampm") & "</TD>")
    57.             .write ("</TABLE>")
    58.             .write ("</DIV>")
    59.             .write ("</BODY>")
    60.             .write ("</HTML>")
    61.         End With
    62.        
    63.     End If
    64.     rs.Close
    65.     Set rs = Nothing
    66.     fso_ts.Close
    67.     Set fso_ts = Nothing
    68.     Set fso_file = Nothing
    69.     Set fso = Nothing
    70.    
    71.     If OpenReport Then ShellExecute 0, "Open", ReportFile, 0, 0, 3
    72. End Sub
    Visit my PROJECTS @ www.asprojects.com

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Thanks

    This is not exactly what I need... but I can certainly use the ideas...


    Thanks a lot for responding..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width