Exporting to folder

creyn

Board Regular
Joined
Sep 16, 2016
Messages
127
I want to have a file exported from a query to a folder. The problem is that this database is used by multiple people and that folder can be located in different drives. How can I use the network name to export to this folder? Below is the code that I am using to do my export. It errors out when I include the network drive as part of the file name.

Option Compare Database

Private Sub Command2_Click()
Dim MyFolder As String
Dim MyFile As String
Dim MyFolder2 As String
Dim FilePath As String
Dim FileContent As String
Dim TextFile As Integer
Dim MyFile2 As String
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Show
.InitialFileName = .SelectedItems.Item(1)
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * from NewBadRecips"
MyFolder2 = .InitialFileName
MyFile = Dir(MyFolder2)
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * from NewBadRecips"
DoCmd.TransferText acImportDelim, "Import Specification", "NewBadRecips", MyFile, True
DoCmd.TransferSpreadsheet transferType:=acExport, TableName:="NewBadRecipsQuery", _
filename:="\\NAEAST.AD.JPMORGANCHASE.COM\AMERTSS$\TSSTSERV\FLSHARE05\DATA18\LIST MAINTENANCE\FRAUD- RETAIL\CLR Templates\NewBadRecipsQuery.xlsx", hasfieldnames:=True
Name "K:\LIST MAINTENANCE\FRAUD- RETAIL\CLR Templates\NewBadRecipsQuery.xlsx" As "K:\LIST MAINTENANCE\FRAUD- RETAIL\CLR Templates" & MyFile
DoCmd.SetWarnings False
MsgBox "Process Complete"
End With
End Sub
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I changed the export to DoCmd.OutputTo ObjectType:=acOutputQuery, ObjectName:="NewBadRecipsQuery", OutputFormat:=acFormatXLSX, Outputfile:="\\NAEAST.AD.JPMORGANCHASE.COM\AMERTSS$\TSSTSERV\FLSHARE05\DATA18\LIST MAINTENANCE\FRAUD- RETAIL\CLR Templates\NewBadRecipsQuery.xlsx". And this is the error I keep receiving: Can't Save The Output Data To The File You've Selected

Does anyone have a fix for this?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,477
Messages
6,130,880
Members
449,603
Latest member
dizze90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top