OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Export data from MS Access Database to OpenOffice Calc

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
HKComputer
Newbie
Newbie


Joined: 31 Jan 2007
Posts: 1

PostPosted: Wed Jan 31, 2007 10:32 am    Post subject: Export data from MS Access Database to OpenOffice Calc Reply with quote

What code do I use to export directly out of an Access Database to a Calc file? Does OpenOffice have to be installed? Does my project need a reference to an OpenOffice object or can I use late binding?

Here's the code I'm currently using. This opens Excel and creates the sheet based on the data I exported. (Or does it create the sheet and then open Excel?!)

Dim objXL As Object
Dim objWB As Object
Dim strFile As String
Dim i As Integer, strFileName As String

'Open a recordset for your query
'Set rs = CurrentDb.OpenRecordset(sCriteria)

'Create a new excel document
On Error GoTo Err_cmdExport_Click
Set objXL = CreateObject("Excel.Application")

'To create new workbook
Set objWB = objXL.Workbooks.Add

'Create header row
For i = 0 To rst1.Fields.Count - 1
objWB.Sheets(1).Cells(1, i + 1).Value = rst1.Fields(i).Name
Next i

'Copy data - start from A2
objWB.Sheets(1).Range("A2").CopyFromRecordset rst1

If Nz(Me.txtFileName, "") = "" Then
strFileName = "DataExport"
Else
strFileName = Me.txtFileName
End If
'Set name of file to save to
strFile = tLookup("ExportLocation", "tblSettings") & strFileName & (Replace(CStr(Date), "/", "")) & ".xls"

'To save as a new file, delete existing file if it exists
If Dir$(strFile) <> "" Then Kill strFile
objWB.SaveAs strFile

'CLOSE DOWN
objWB.Close
objXL.Quit

Set objWB = Nothing
Set objXL = Nothing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group