AddItem skips every other item

G

Guest

In Access 2003 SP2
I created a combo box that displays folders. Using the AddItem method, every
other item is skipped. I cannot see why. Here is the code placed in the LOAD
event of the form:

Private Sub Form_Load()
' Ensure that the cboDirectories combo box gets list of
' available folders in the specified drive.
Dim mydir As String
mydir = Dir("S:\*.", vbDirectory)
' Don't bother adding first item as it is the root directory
Do Until Dir = ""
mydir = Dir
Me.cboDirectories.AddItem Item:="S:\" & mydir & "\"
Loop
End Sub

So ... if the S: drive contains the following directories:
ALC-Shared
EBB
ESC Building
FoodServ
Reorg
StudentServ
Tech

The combo box only displays:
ALC-Shared
ESC Building
Reorg
Tech

Thanks for any thoughts! It must be something amazingly obvious?
 
G

Guest

MY BAD! I figured it out, after all. I was calling the DIR function twice
within the loop, thereby skipping every other name. Silly me.

I therefore rewrote the procedure as follows:
MyPath = "S:\"
mydir = Dir(MyPath, vbDirectory)
' Now loop through drive and get the other directories
Do While mydir <> ""
If mydir <> "." And mydir <> ".." Then
Me.cboDirectories.AddItem Item:=MyPath & mydir & "\"
End If
mydir = Dir
Loop

'***!
 
G

Guest

Code the following msgbox:

Do Until Dir = ""
mydir = Dir
msgbox mydir
Me.cboDirectories.AddItem Item:="S:\" & mydir & "\"
Loop

That will tell you if it is your loop or the 'dir' that is returning the
wrong result.
Did you take a look at the value list in the combo box properties?
My guess is you don't have the separator character correct.

-Dorian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top