Solved

export an Access query to a predefined excel file layout

Posted on 2004-03-30
3
487 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
3 Comments
 
LVL 2

Expert Comment

by:thescot
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. Exactly what i was looking for.

Regards,

Charley
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now