Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

export an Access query to a predefined excel file layout

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

610 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