Import file with spaces in file name

R

Reggie

Hi and TIA! I'm trying to import files into my db. All works well if the
file name has no spaces, but if there are spaces it bombs out. Is this a
common feature or is there a way to allow my uses to import files with
spaces in the file name. Thanks for you time!
 
J

John W. Vinson

Hi and TIA! I'm trying to import files into my db. All works well if the
file name has no spaces, but if there are spaces it bombs out. Is this a
common feature or is there a way to allow my uses to import files with
spaces in the file name. Thanks for you time!

Put the filename in quotes. I presume you're using TransferText in VBA code?
If not please explain the context.
 
R

Reggie

John W. Vinson said:
Put the filename in quotes. I presume you're using TransferText in VBA
code?
If not please explain the context.

John, Sorry I wasn't more specific. Here's the code I am using. Thanks
once again for you time and help.

Dim strTable As String
Dim strfilter As String

strTable = "tblAMCR_Import_Temp"
strfilter = ""
strfilter = OpenFileExt(strfilter, "Excel Files(*.XLS)", "*.XLS")
If IsNull(strfilter) Then
Exit Sub
Else
DoCmd.TransferSpreadsheet acImport, , strTable, strfilter, False
End If
 
J

John W. Vinson

John, Sorry I wasn't more specific. Here's the code I am using. Thanks
once again for you time and help.

Dim strTable As String
Dim strfilter As String

strTable = "tblAMCR_Import_Temp"
strfilter = ""
strfilter = OpenFileExt(strfilter, "Excel Files(*.XLS)", "*.XLS")
If IsNull(strfilter) Then
Exit Sub
Else
DoCmd.TransferSpreadsheet acImport, , strTable, strfilter, False
End If

Now I'm really confused. There are no variable filenames here... do you mean
that it works for tblAMCR_Import_Temp but fails if the filename is

tblAMCR Import Temp.xls

or what?
 
R

Reggie

John W. Vinson said:
Now I'm really confused. There are no variable filenames here... do you
mean
that it works for tblAMCR_Import_Temp but fails if the filename is

tblAMCR Import Temp.xls

or what?

No. The open file dialog opens (strfilter = OpenFileExt(strfilter, "Excel
Files(*.XLS)", "*.XLS")). The user selects the file (ex. C:\MyFile or
whatever) and this is placed into strfilter(variable file name).
tblAMCR_Import_Temp is the table I am transfering the excel spreadsheet
into. It works if strfilter = C:\MyFile but not if C:\My File.
 
J

John W. Vinson

No. The open file dialog opens (strfilter = OpenFileExt(strfilter, "Excel
Files(*.XLS)", "*.XLS")). The user selects the file (ex. C:\MyFile or
whatever) and this is placed into strfilter(variable file name).
tblAMCR_Import_Temp is the table I am transfering the excel spreadsheet
into. It works if strfilter = C:\MyFile but not if C:\My File.

Ok. Sorry, brainfade there!

Try surrounding the filename with quotemarks:

Const Q = """"
strfilter = Q & OpenFileExt(strfilter, "Excel Files(*.XLS)", "*.XLS") & Q

so that it sees "C:\My File" with the quotes.
 
R

Reggie

John W. Vinson said:
Ok. Sorry, brainfade there!

Try surrounding the filename with quotemarks:

Const Q = """"
strfilter = Q & OpenFileExt(strfilter, "Excel Files(*.XLS)", "*.XLS") &
Q

so that it sees "C:\My File" with the quotes.


John it didn't like:
strfilter = Q & OpenFileExt(strfilter, "Excel Files(*.XLS)", "*.XLS") & Q

however this worked like a champ:

strfilter = OpenFileExt(cDQ & strfilter & cDQ, "Excel Files(*.XLS)",
"*.XLS")

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top