Filesearch

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the followin code to fill a comboBox with the names of csv files
found in a folder. I use the comboBox to select a file to transfer into a
table. After desplaying the data in the file and saving it into other
tables, i delete the original file with the Kill function. I then set the
combobox rowsource to "" and call this procedure again. The problem is that
the file.csv that I looked at and then Killed still showes up in the combobox
again. A check if the directory confirms that it is gone, but i cand keep
the name out of my combobox. (MyPath is a public string)

Private Sub LoadCombBox()
Dim id As String
Dim x As Integer
With Application.FileSearch
'.NewSearch
.LookIn = myPath
.FileName = "*.csv"
If .Execute > 0 Then
For x = 1 To .FoundFiles.Count
id = .FoundFiles(x)
id = Replace(id, myPath, "")
id = Replace(id, ".csv", "")

Me.GRNName.AddItem id
Next x
Else
MsgBox "No New Chem Results Found"
stopCmd_Click
End If
End With
End Sub
 
R.Payne said:
I am using the followin code to fill a comboBox with the names of csv
files found in a folder. I use the comboBox to select a file to
transfer into a table. After desplaying the data in the file and
saving it into other tables, i delete the original file with the Kill
function. I then set the combobox rowsource to "" and call this
procedure again. The problem is that the file.csv that I looked at
and then Killed still showes up in the combobox again. A check if
the directory confirms that it is gone, but i cand keep the name out
of my combobox. (MyPath is a public string)

Private Sub LoadCombBox()
Dim id As String
Dim x As Integer
With Application.FileSearch
'.NewSearch
.LookIn = myPath
.FileName = "*.csv"
If .Execute > 0 Then
For x = 1 To .FoundFiles.Count
id = .FoundFiles(x)
id = Replace(id, myPath, "")
id = Replace(id, ".csv", "")

Me.GRNName.AddItem id
Next x
Else
MsgBox "No New Chem Results Found"
stopCmd_Click
End If
End With
End Sub

It seemed to work as expected in a simple test I set up. Are you sure
your code is being executed in the right sequence? I suggest you put
some breakpoint at various points in your code and verify the sequence
of execution.
 
I had used Break Points and everything was as it should be up until I re-read
the file names. It seems to read the same names in that it did the first
time. I have gotten around this by using the Dir() function, but it still
bothers me that this won't work.
 
Back
Top