Export Access table without fieldnames

L

LAlbee

How do I go about exporting a table into excel without including the
fieldnames in the first row of data?
 
K

Klatuu

Neither the TransferSpreadsheet nor the OutPutTo methods will do this. Your
only option (other than opening the spreadsheet and deleting the row with the
field names) is to use Automation to open the spreadsheet as an Excel object
in Access and use the CopyFromRecordset method of the Range object in the
Excel Object Model to load the data into Excel.
 
L

LAlbee

Thanks, can you give me any more details on how to accomplish this, I don't
know much about VB.
 
K

Klatuu

If you are not familiar with VBA, it will be very difficult for you to use
this approach. It really does take some fairly advanced VBA skills to
accomplish. This is because using Automation to control Excel, if not done
correctly, can create additional instances of Excel in the Task Manager
Processes tab and cause the user to not be able to use Excel.

Here is some sample code from one of my applications. I extracted those
lines of code that are pertinent; however, this may not be complete. It will
give you an idea of what is required to manipulate Excel from Access.

Dim xlApp As Object 'Application Object
Dim xlBook As Object 'Workbook Object
Dim xlSheet As Object 'Worksheet Object
Dim blnExcelWasNotRunning As Boolean

'Set up the necessary objcts
On Error Resume Next ' Defer error trapping.
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
blnExcelWasNotRunning = True
Set xlApp = CreateObject("excel.application")
Else
DetectExcel
End If
Err.Clear ' Clear Err object in case error occurred.
On Error GoTo Build_XL_Report_ERR
xlApp.DisplayAlerts = False
xlApp.Interactive = False
xlApp.ScreenUpdating = False
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.ActiveSheet

'Create the Recordset
Set qdf = CurrentDb.QueryDefs("qselSCCBhdr")
qdf.Parameters(0) = Me.cboResource
qdf.Parameters(1) = Me.cboPeriod
Set rstItms = qdf.OpenRecordset(dbOpenSnapshot, dbReadOnly)

'Be sure there are records to process
rstItms.MoveLast
rstItms.MoveFirst
lngItmCount = rstItms.RecordCount
If lngItmCount = 0 Then
MsgBox "No Data Found For This Report", vbInformation + vbOKOnly,
"Data Error"
GoTo Build_XL_Report_Exit
End If

xlSheet.Cells(2, 1).CopyFromRecordset rstItms

xlBook.Close
If blnExcelWasNotRunning = True Then
xlApp.Quit
Else
xlApp.DisplayAlerts = True
xlApp.Interactive = True
xlApp.ScreenUpdating = True
End If
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
rstItms.Close
Set rstItms = Nothing
--------------------------------
Sub DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top