473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
3 1507
MMcCarthy
14,534 Expert Mod 8TB
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
NDayave
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
32,556 Expert Mod 16PB
Would you mind posting your solution then :)
That will give a solution to anyone researching a similar question.
Feb 26 '07 #4

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

Similar topics

1
by: M Wells | last post by:
Hi All, I am developing an Access 2003 project application with the back end in SQL Server 2003. I have a master form that tracks projects, and several subforms on it that track various...
9
by: Paul H | last post by:
I have developed several databases in Access. I know VBA. I am making the jump to VB and am currently using Visual basic 2005 Express. Can anyone give me a snippet that will show me how to list...
3
by: Robert W. | last post by:
I have a SQL Server table called "ClosedMonths" that contains two pertinent fields: Yearx Monthx 2000 1 2000 2 2000 3 I want to simply query this...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.