Solved

Acess VBA - Export query to Excel + Create New Sheets

Posted on 2006-11-15
4
1,422 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
Comment Utility
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
Comment Utility
typo

try this - specify a range
eg

Sheet2$A1:Z65536

instead of Sheet2
0
 
LVL 1

Author Comment

by:gigantorTRON
Comment Utility
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
Comment Utility
No probs :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

16 Experts available now in Live!

Get 1:1 Help Now