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

File Exists problem ??? 1

Status
Not open for further replies.

dreman

Programmer
Joined
Jan 16, 2002
Messages
272
Location
US
I have a form that has a key to backup a table called Clients
I created a function:
Private Function FileExists(ByVal FileName As String) As Boolean
FileExists = Len(Dir(FileName)) > 0
End Function

Public Backup_click()
Dim StrFile as String
StrFile = "Clients"
if fileExits(strFile) = False then
msgbox "File Does not exists"
End if
'do other stuff
End Sub

I am getting File Does not exists at all time even thought the table exists.
Please advise,
thank you.
 
Hi dreman,

1. You need to have the Extension for the File you are checking.

2. You've misspelt FileExists in the Example, anyway.

Private Function FileExists(ByVal FileName As String) As Boolean
FileExists = Len(Dir(FileName)) > 0
End Function

Public Backup_click()
Dim StrFile as String
StrFile = "Clients.mdb"
if fileExists(strFile) = False then
msgbox "File Does not exists"
End if
'do other stuff
End Sub

Good Luck

Bill
 
Bill:
thanks for the help but Clients is a table within .mdb database. ???
As for the mispelled, it was accidental...
Thank you.
dré
 
Hi dreman,

This wasn't easy but should do what you want, paste this into your Form:

Private Function File_Exists(ByVal FileName As String) As Boolean
Dim dbs As DAO.Database, tdf As DAO.TableDef
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
If tdf.Name = FileName Then
File_Exists = True
Exit Function
Else
File_Exists = False
End If
Next tdf
End Function

This in the On Click event of a Button on the Form:

MsgBox File_Exists("Clients")


Regards

Bill


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top