Question : Error handling for Import TransferText Macro

I have a Macro that uses TransferText to import a specific text file name.  If the file does not exist, i want the Macro to halt/quit/ PRIOR to the TransferText attempting the import and erroring out.  Basically, I need to validate that the file exists before TransferText attempts to execute.  Is there an Action available for this?

Note, TranferText looks for a file name with with the following property as the import file is labeled with a date format:

="\\filepath\FileName" & Format(Date()-1,"mmddyy") & ".TXT"

Thanks in advance!

Answer : Error handling for Import TransferText Macro

Leaving in only the necessary stuff:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Function TransferTextTest()
Dim strPathName As String 

strPathName = "\\server2\IT\Databases\XPN\from_xpn\C01398P01NTC" & Format(Date - 1, "mmddyy") & ".TXT"

'Dir returns zero length string if file not found:
If Len (Dir (strPathName) & "") = 0 Then 
   MsgBox "File not found" 
Else 
   DoCmd.TransferText acImportDelim, "xpn trigger import spec", "TRIGGER_IMPORT_MASTER", strPathName , False
End If 
End Function 
Random Solutions  
 
programming4us programming4us