Public Function xxx()
Dim frst As New ADODB.Recordset
Dim strSql2 as String
strSql2 = "SELECT tblAnalystCustXRef.TBPPath, tblAnalystCustXRef.DefaultCustNbr, tblAnalystCustXRef.AnalystName, tblAnalystCustXRef.PayMethod, tblAnalystCustXRef.ClaimTypeDesc, '' as ArchFileName, tblAnalystCustXRef.ArchivePath " & _
"FROM tblAnalystCustXRef " & _
"WHERE tblAnalystCustXRef.TBPPath IS NOT NULL " & _
"AND tblAnalystCustXRef.Active = 1 " & _
"AND tblAnalystCustXRef.AnalystName = '" & _
Forms!frmLogon.cboLogon & "';"
With frst
'I tried both of these
'.Open strSql2, CurrentProject.Connection, adOpenStatic, adLockReadOnly 'Original
'.Open strSql2, CurrentProject.Connection, adOpenDynamic, adLockOptimistic 'Changed to allow updates
Do While Not .EOF
' if the folder exists,
If Not frst(0) Is Nothing Then
If fso.FolderExists(frst(0)) Then
' set the folder
Set fld = fso.GetFolder(frst(0))
' loop through the files in the folder,
For Each fil In fld.Files
' if the file is one of the target types,
If LCase(Right(fil.Name, 3)) = "xls" _
Or LCase(Right(fil.Name, 4)) = "xlsx" _
Or LCase(Right(fil.Name, 3)) = "txt" _
Or LCase(Right(fil.Name, 3)) = "csv" Then
'This section is added to copy the file name to ArchFileName field in the recordset
If InStr(fil.Name, "'") > 0 Then
CurrentDb.Execute "UPDATE frst SET frst(5)='" & fil.Name & _
"' WHERE frst(0)='" & frst(0) & _
"' AND frst(1)=" & frst(1) & _
" AND frst(2)='" & frst(2) & _
"' AND frst(3)='" & frst(3) & _
"' AND frst(4)='" & frst(4) & "';"
|