Solved

Acess VBA - Export query to Excel + Create New Sheets

Posted on 2006-11-15
4
1,423 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…

914 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

17 Experts available now in Live!

Get 1:1 Help Now