?
Solved

export an Access query to a predefined excel file layout

Posted on 2004-03-30
3
Medium Priority
?
527 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
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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 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