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

Checking that a file exists before importing it

Status
Not open for further replies.

johnster

Programmer
Jan 3, 2001
9
GB
I have some code that imports and appends a file. does anyone know a way to check that the file exists before the code tries to import it.

Thanks,

John.
 
Try this:

Function fExistTable(strTableName As String) As Integer
Dim db As Database
Dim i As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
fExistTable = False
db.TableDefs.Refresh
For i = 0 To db.TableDefs.Count - 1
If strTableName = db.TableDefs(i).Name Then
'Table Exists
fExistTable = True
Exit For
End If
Next i
Set db = Nothing
End Function

HTH

Dan
 


Hi johnster

Check out FileSystemObject.


Stew "Even a stopped clock tells the right time twice a day."
 
If it's a file you're importing, and not an Access table,
try the DIR function that's built into Access.

If Len(Dir(path and file name)) <> 0 then
Import File
End if

Uncle Jack


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top