Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transferspreadsheet filename optional? 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I want to export to XLS a query and I want the user to have the option to chose where and what to save the file as.

According to :
FileName is 'optional' and I assumed that omitting it, means you get some sort of file dialog GUI to manage the filename and path.

However, when I use
Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "myQueryNamne"

I get an error
The action or method requires a File Name argument
Colour me confused, because the docs say it is optional?

What error can't I see?

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
I achieved what I wanted with this...

Code:
Global Const msoFileDialogSaveAs As Integer = 2

' export query to XLS
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "myQuery", SaveFileAs, True

Public Function SaveFileAs() As String

    Dim fd As Object
    
    On Error GoTo Err_SaveFileAs
 
    Set fd = Application.FileDialog(msoFileDialogSaveAs)
 
    If fd.Show = True Then
        fd.AllowMultiSelect = False
        If fd.SelectedItems(1) <> vbNullString Then
            SaveFileAs = fd.SelectedItems(1)
        End If
    End If
 
Exit_SaveFileAs:

    Set fd = Nothing
    Exit Function
 
Err_SaveFileAs:

    MsgBox "Error " & Err & ": " & Error(Err)
    Resume Exit_SaveFileAs
    
End Function

Though the question still stands, why do I get an error for omitting what the docs say is an optional argument?



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Thanks Mike, it clearly states it is required in those docs...
The name of the spreadsheet file to import from, export to, or link to. Include the full path. This is a required argument.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top