By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

Exporting from queries in vb into excel with Header

P: 17
Hi Guys,

Can anyone help me with this problem please. I cant export a queries that I wrote in vb script into excel with Header according into the queries that I wrote.
I can export the data but without the header. I want additional header from the queries.

Thanks guys.
Sep 25 '07 #1
Share this Question
Share on Google+
3 Replies

P: 17
This is my code to export into excel. So where should I add the Header??

Public Function ExportToFile(ByVal filepath As String, ByVal rs As DAO.Recordset, ByRef columnStart As Integer) As Boolean

Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim fld As DAO.Field
Dim x As Integer
Dim i As Integer

Set xl = New Excel.Application

If FileExists(filepath) And Not filepath = "" Then
Set wb = xl.Workbooks.Open(filepath, False, False)
Set ws = wb.Worksheets.Add
Set wb = xl.Workbooks.Add
Set ws = wb.Worksheets(1)
End If

i = 1
Do While Not rs.EOF()
x = columnStart
For Each fld In rs.fields
Select Case fld.Type
Case dbBinary, dbGUID, dbLongBinary, dbVarBinary
' This type of data can't export to excel
Case Else
ws.Cells(i, x).Value = rs.fields(fld.Name).Value
x = x + 1
End Select
i = i + 1

xl.Visible = True
ExportToFile = True

' Release the objects.
Set ws = Nothing
Set wb = Nothing
Set xl = Nothing
Exit Function

ExportToFile = False
MsgBox "Problem with the reading of the date into the file." & vbCr & Err.Description, vbCritical, csAppName
Resume exit_errorhandler:

End Function
Sep 25 '07 #2

P: 17
anyone? please help me.
Sep 27 '07 #3

P: 17
please. how do you do to export data into excel with header?
Oct 2 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.