I'm trying to loop through a directory based on locations and file names that are in a table. Everytime I run the code I get a bad file name/count when trying to set strFileName. The files do exist and will work if I hardcode these values into the code. Any help would be apprectiated.
Code:
Function test()
Dim recFileImport As Recordset
Dim strFileImport As String
Dim strLocation As String
Dim strExtention As String
Dim strPrefix As String
Dim strSpec As String
Dim strTable As String
Dim strLayout As String
Dim strFileName As Variant
strFileImport = "SELECT * FROM tblFileImport;"
Set recFileImport = CurrentDb.OpenRecordset(strFileImport)
With recFileImport
Do Until .EOF
strLocation = ![fli_location]
strExtention = ![fli_extention]
strPrefix = ![fli_prefix]
strSpec = ![fli_spec]
strTable = ![fli_table]
strLayout = ![fli_tran_type]
'strLocation = "C:\My Documents\"
strFileName = Dir$(strLocation & strExtention)
While strFileName <> ""
DoCmd.TransferText strLayout, strSpec, strTable, strFileName
strFileName = Dir$()
Wend
.MoveNext
Loop
End With
End Function