Hello!
I have a db that needs to export a query to an excel spreadsheet in the my documents folder on the users hard drive. I can make that work fine but if the directory does not exist, I need to have it created and then have the file put in the new directory. Here is the code that I use to export if the dir exists.
Private Sub cmdExportFile_Click()
On Error GoTo Err_cmdExportFile_Click
Dim Myfile
Myfile = "C:\Documents and Settings\" & winUserName & "\My Documents\INV\ " & "query1.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Query1", Myfile, True
MsgBox ("This file has been saved to your documents")
Exit_cmdExportFile_Click:
Exit Sub
Err_cmdExportFile_Click:
MsgBox Err.Description
Resume Exit_cmdExportFile_Click
End Sub
I have tried a couple of things to create a new dir but it always errors out.
This is the first code that I used that did not work. I added this directly after MyFile.
If Not oFileObject.FolderExists("C:\Documents and Settings\" & winUserName & "\My Documents\INV") Then
oFileObject.CreateFolder "C:\Documents and Settings\" & winUserName & "\My Documents\INV"
End If
Any help would be great.
Thanks.
I have a db that needs to export a query to an excel spreadsheet in the my documents folder on the users hard drive. I can make that work fine but if the directory does not exist, I need to have it created and then have the file put in the new directory. Here is the code that I use to export if the dir exists.
Private Sub cmdExportFile_Click()
On Error GoTo Err_cmdExportFile_Click
Dim Myfile
Myfile = "C:\Documents and Settings\" & winUserName & "\My Documents\INV\ " & "query1.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Query1", Myfile, True
MsgBox ("This file has been saved to your documents")
Exit_cmdExportFile_Click:
Exit Sub
Err_cmdExportFile_Click:
MsgBox Err.Description
Resume Exit_cmdExportFile_Click
End Sub
I have tried a couple of things to create a new dir but it always errors out.
This is the first code that I used that did not work. I added this directly after MyFile.
If Not oFileObject.FolderExists("C:\Documents and Settings\" & winUserName & "\My Documents\INV") Then
oFileObject.CreateFolder "C:\Documents and Settings\" & winUserName & "\My Documents\INV"
End If
Any help would be great.
Thanks.