psulions83
Board Regular
- Joined
- Nov 16, 2015
- Messages
- 127
Hi,
I am new to writing loop statements so I apologize if this is a previous topic but I could not find anything pertinent before posting.
I have a loop statement that reads from a file and loops. It brings in specified files from a location in the loop. Can I have this loop skip over a file if it does not exist in the folder? The below works as is unless I do not have one of the specified files in the folder. ie it calls for files 1-5 but i only have files 1, 2, 3 & 5.
I am new to writing loop statements so I apologize if this is a previous topic but I could not find anything pertinent before posting.
I have a loop statement that reads from a file and loops. It brings in specified files from a location in the loop. Can I have this loop skip over a file if it does not exist in the folder? The below works as is unless I do not have one of the specified files in the folder. ie it calls for files 1-5 but i only have files 1, 2, 3 & 5.
Code:
Public Function loopTable()
Dim strSQL As String
Dim rs As DAO.Recordset
' Define TableFields
Dim ImprtSpec, TblNm, FileNm As String
strSQL = "SELECT * FROM Tbl_Data"
Set rs = CurrentDb.OpenRecordset(strSQL)
If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
While (Not rs.EOF)
ImprtSpec = rs.Fields("ImportSpecNm") 'define the field you want to return data
TblNm = rs.Fields("TableName")
FileNm = rs.Fields("FileName")
DoCmd.TransferText acImportDelim, ImprtSpec, TblNm, Application.CurrentProject.Path & "\" & FileNm, True
Debug.Print rs.Fields("FileName")
Last edited: