?
Solved

export an Access query to a predefined excel file layout

Posted on 2004-03-30
3
Medium Priority
?
517 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 500 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

752 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