Solved

Acess VBA - Export query to Excel + Create New Sheets

Posted on 2006-11-15
4
1,424 Views
Last Modified: 2008-02-01
Hi all,
Just a quick question... I have an access DB that exports a query called "lastName" to Excel. This works fine, but I want to be able to create a new sheet based on a variable called textInput.

Here is my code right now...

Private Sub Command6_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim querySQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("lastName")
querySQL = "My SQL query..."
If Me.searchText.Value = "" Then
    MsgBox ("Invalid Input")

Else
qdf.SQL = querySQL
DoCmd.OpenQuery "lastName"
Set qdf = Nothing
Set db = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "lastName", "C:\Desktop\MyField.xls", True

End If
End Sub


The query is called "lastName."

I want to take the results of that same query, but export it to a different sheet name. Any ideas?
0
Comment
Question by:gigantorTRON
  • 3
4 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17948706
try specifing the sheetname
e.g

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "lastName", "C:\Desktop\MyField.xls", True, "Sheet2!"
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 260 total points
ID: 17948715
typo

try this - specify a range
eg

Sheet2$A1:Z65536

instead of Sheet2
0
 
LVL 1

Author Comment

by:gigantorTRON
ID: 17948793
Wow, I really thought that it would be harder than that for some reason!

Thanks for the quick response!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17948827
No probs :)
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

772 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