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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export a Form to Excel

Status
Not open for further replies.

theSizz

Technical User
Apr 22, 2002
93
0
0
US
I have the following code:

Code:
Private Sub Command71_Click()

On Error GoTo Err_Command71_Click

 Dim stDocName As String

    stDocName = "frmPriceUSF"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
    stDocName, "C:\Documents and Settings\Administrator\Desktop\SIZZLER\INVENTORY\PricesUSF.xlsx"
    
MsgBox "Spreadsheet was created."
Exit_Command71_Click:
Exit Sub

Err_Command71_Click:
    MsgBox Err.Description
    Resume Exit_Command71_Click

End Sub


The problem is that I get an error message that states "DB engine could not find the object frmPriceUSF, make sure that the object exists etc. etc.

Well this is a valid form that does exist and yes the name is spelled correctly in the code.
I've used this code to transfer querys to an excel spreadsheet and no problem the code does the job.
In fact if I change the stDocName variable to qryPriceABC which is another object in the database the code runs fine.
Is there a different syntax for exporting form objects?

Any help would be appreciated.
Thank You
 
If you search in Help for TransferSpreadsheet, you'll see that you can specify a Table or Query - but not a Form.

Have you tried saving the form's Record Source as a Query, and then exporting that?

Max Hugen
Australia
 
Yes I realize that now and that will be my course of action.
I'll just use the query that is the record source for the form.
Thanks for pointing that out to me.

Appreciate your time.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top