By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Listbox doubles up on directory contents...why? Access 2000

P: 92
How do,

I have a (Access 2000) list box that returns all the files in a directory (CurrentProject.Path & "\Backup") to be used to restore backup of the database. My problem is that the first row of the list always has a double name ie:

Row 1: <Filename1><Filename1>
Row 2: <Filename2>
Row 3: <Filename3>
etc.

I would like to either get rid of the second filename in row 1, or totally mask out the first row, as either solution is acceptable.

Thats all the code for the list box and executes on Form_Load (No more, no less)
Expand|Select|Wrap|Line Numbers
  1. Dim strDir As String
  2. Dim strFile As String
  3. Dim strFolder As String
  4.  
  5.  
  6. strFolder = CurrentProject.Path & "\Backup"
  7. strDir = strFolder
  8. lstRestore.RowSourceType = "Value List"
  9. lstRestore.RowSource = ""
  10. strFile = Dir(strDir & "\*")
  11. If strFile = "" Then
  12.   msgbox ("No files found in " & strDir)
  13.   Exit Sub
  14. End If
  15. Do While strFile <> ""
  16.   If lstRestore.RowSource = "" Then
  17.     lstRestore.RowSource = strFile
  18.   Else
  19.     lstRestore.RowSource = lstRestore.RowSource & strFilename
  20.     strFile = Dir()
  21.     If strFile <> "" Then lstRestore.RowSource = lstRestore.RowSource & ";"
  22.   End If
  23. Loop
  24. lstRestore.Value = Null
  25.  
I think the problem is with the line "lstRestore.RowSource = lstRestore.RowSource & strFilename" (6th from bottom), but when i tried deleting either aspect of the rowsource a full file list of the directory wasn't given.

All help is appreciated,

NDayave
Feb 22 '07 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Dim strDir As String
  2. Dim strFile As String
  3. Dim strFolder As String
  4.  
  5. strFolder = CurrentProject.Path & "\Backup"
  6. strDir = strFolder
  7. lstRestore.RowSourceType = "Value List"
  8. lstRestore.RowSource = ""
  9. strFile = Dir(strDir & "\*")
  10. If strFile = "" Then
  11.   msgbox ("No files found in " & strDir)
  12.   Exit Sub
  13. End If
  14. Do While strFile <> ""
  15.   If lstRestore.RowSource = "" Then
  16.     lstRestore.RowSource = strFile
  17.     strFile = Dir()
  18.     If strFile <> "" Then lstRestore.RowSource = lstRestore.RowSource & ";"
  19.   Else
  20.     lstRestore.RowSource = lstRestore.RowSource & strFilename
  21.     strFile = Dir()
  22.     If strFile <> "" Then lstRestore.RowSource = lstRestore.RowSource & ";"
  23.   End If
  24. Loop
  25. lstRestore.Value = Null
  26.  
Feb 22 '07 #2

P: 92
I appreciate the help, but although the code has got rid of the double filename, it now only shows the first file in the Directory. I have however found a solution, but am grateful nontheless for your time.

NDayave
Feb 22 '07 #3

NeoPa
Expert Mod 15k+
P: 31,186
Would you mind posting your solution then :)
That will give a solution to anyone researching a similar question.
Feb 26 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.