Import text file using a wildcard

G

Guest

I am running the following code to import all text files that all start with
the same 12 characters:
' Set the parameters to import the text file
If Right(Me!txtFilePath, 1) = "\" Then
strPath = \\mdb8\Global
Else
strPath = \\mdb8\Global& "\"
End If
strFileName = "GlobalImport*.txt"

If FileExists(strPath & strFileName) = False Then
msgbox "File " & strPath & strFileName & " Does not exist!",
vbCritical + vbOKOnly, "No File..."
GoTo ExitImport
Else
GetName = Dir(strPath & strFileName)
End If
'Does file name exist in directory
Public Function FileExists(FName As String) As Boolean
On Error GoTo Err_FileExists
FileExists = False
FileExists = (Dir(FName) <> "")
Exit_FileExists:
Exit Function
Err_FileExists:
Select Case Err.Number
Case 76
FileExists = False
Resume Exit_FileExists
Case Else
msgbox Err.Number & vbCrLf & Err.Description, , "FileExistError"
Resume Exit_FileExists
End Select
End Function

When I run the code it will not return any of the text files located in
"//mdb8/Global". However, if I add a drive letter it works. This is not
practical since I am referencing a network drive. Any ideas on how I can get
about this???

Thanks
Database girl
 
G

Guest

A different approach would be to use a drive letter you know is available on
every machine like P: using the shell command

Shell "net use P: \\server\foldername"

then you could reference the drive letter.

I sure this is not as good as Doug's answer.
 
G

Guest

Doug,

I had forgotten to put in the share name when I referenced the strpath in my
code. Silly me!

Thanks for your help.
 

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