Solved

export an Access query to a predefined excel file layout

Posted on 2004-03-30
3
508 Views
Last Modified: 2012-08-14
How can i export an Access query to a predefined excel file layout ?

My query named Salary have the following fields.

BranchCode
Employee
Salary Date
PostCurrency
PostAmount
Narration

How can i export the contents of this query into an Excel File C:\ TEST.XLS having sheet  named "Salary", starting From A3:F3?

ie Branch code value goes into A3, Employee value into B3, Salary Date into C3, PostCurrency into D3, PostAmount into E3 and Narration into F3.

I have hundreads of records in query.

Regards,

Charley


0
Comment
Question by:chthomas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:thescot
ID: 10712098
You can use the TransferSpreadsheet function in a Macro.

Create a macro and select TransferSpreadsheet,
Choose your table,
Set the Actions for the TransferSpreadsheet and in the Range set it to A3:F3,
Run the Macro and the required cells will be populated.
0
 
LVL 4

Accepted Solution

by:
goliak earned 125 total points
ID: 10712192
Here is it. You just need to change tblName.

Private Sub Button0_Click()
Dim xls As Excel.Application
Dim rs As DAO.Recordset
Dim j As Integer 'Quantity of fields in rs object
Set xls = CreateObject("Excel.Application")
xls.Visible = True
xls.Workbooks.Open "C:\Test.xls"
Set rs = CurrentDb.OpenRecordset("SELECT BranchCode, Employee, [Salary Date], PostCurrency, PostAmount, Narration FROM tblName")
rs.MoveLast
rs.MoveFirst
For j = 0 To 5
    While Not rs.EOF
        Select Case j
        Case 0
        xls.Cells(rs.AbsolutePosition + 4, "A") = rs(j)
        rs.MoveNext
        Case 1
        xls.Cells(rs.AbsolutePosition + 4, "B") = rs(j)
        rs.MoveNext
        Case 2
        xls.Cells(rs.AbsolutePosition + 4, "C") = rs(j)
        rs.MoveNext
        Case 3
        xls.Cells(rs.AbsolutePosition + 4, "D") = rs(j)
        rs.MoveNext
        Case 4
        xls.Cells(rs.AbsolutePosition + 4, "E") = rs(j)
        rs.MoveNext
        Case 5
        xls.Cells(rs.AbsolutePosition + 4, "F") = rs(j)
        rs.MoveNext
        End Select
    Wend
    rs.MoveFirst
Next
End Sub
0
 

Author Comment

by:chthomas
ID: 10712290
Thanks. Exactly what i was looking for.

Regards,

Charley
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question