|
 |
access thread: Fill a List Box with sorted files
Message #1 by "Michael.Stalford" <michael.stalford@c...> on Wed, 19 Mar 2003 13:01:10 -0700
|
|
Sarah,
Here is the code that sorts the array and then populates the
list box.
Note that I determine how many items and then populate the
array. This is the Microsoft recommended way for using a dynamic array.
You might find people who combine the first loop with populating the
array. I was told that is not the preferred method. Hope you find it
useful....Mike
Private Sub Form_Open(Cancel As Integer)
Dim intCount As Integer
Dim strFileName As String
Dim astrFiles() As String
Dim intFirstCount As Integer
Dim intSecondCount As Integer
Dim strTemp As String
'Set the initial Path. This should be changed to a supporting
directory where
'the txt files reside.
strFileName = Dir("e:\My Documents\") ' Retrieve the first entry.
'Start looping through the directory
'We continue looping through until we
'run out of files in the directory
Do While strFileName <> ""
'Using the string function we can check to see if the
'extension matches what we are looking for.
If Right(strFileName, 4) = ".xml" Then
'We need to findout how many files there are
intCount = intCount + 1
End If
'Get the next file in the list
strFileName = Dir ' Get next entry.
Loop
'Let's make sure there are files.
'If not, then we tell the user and exit
If intCount = 0 Then
MsgBox "There are no Employee Files to import."
Cancel = True
End If
'Redim the dynamic array with the value determined above
'Since arrays are zero based we need to subtract 1.
ReDim astrFiles(intCount - 1)
'Reset the variables
strFileName = Dir("e:\My Documents\")
intCount = 0
'Loop through looking for files again
Do While strFileName <> ""
'Find the matching file
If Right(strFileName, 4) = ".xml" Then
'Put the file name in the array
astrFiles(intCount) = strFileName
'Increment the counter
intCount = intCount + 1
End If
'Get the next file in the list
strFileName = Dir
Loop
'Sort the file names in the array
'This is a simple bubble sort routine
For intFirstCount = 0 To UBound(astrFiles) - 1
For intSecondCount = 0 To intFirstCount
If LCase(astrFiles(intSecondCount)) >
LCase(astrFiles(intSecondCount + 1)) Then
strTempName = astrFiles(intSecondCount + 1)
astrFiles(intSecondCount) = astrFiles(intSecondCount +
1)
astrFiles(intSecondCount + 1) = strTempName
End If
Next
Next
'Populate the list box in sorted order
For intFirstCount = 0 To UBound(astrFiles) - 1
Me.lstFiles.AddItem astrFiles(intFirstCount)
Next
End Sub
-----Original Message-----
From: ROBERTS, Sarah [mailto:Sarah.ROBERTS@w...]
Sent: Wednesday, March 19, 2003 9:56 AM
To: Access
Subject: [access] Re: File List Box
Yes, i would be interested to see it...
I have extended it slightly to pick up all files in the directory (not
just
.txt) and then on_click to open up the file using shell execute.
Sorted would be good though!
Many thanks Mike
-----Original Message-----
From: Michael.Stalford [mailto:michael.stalford@c...]
Sent: 19 March 2003 15:09
To: Access
Subject: [access] Re: File List Box
Sarah,
I am working on fine tuning it a little. I'll be adding them to
a dynamic array and then sorting the files before adding them to the
list box. Let me know if you would like that as well.
Mike
-----Original Message-----
From: ROBERTS, Sarah [mailto:Sarah.ROBERTS@w...]
Sent: Wednesday, March 19, 2003 9:03 AM
To: Access
Subject: [access] Re: File List Box
Michael
This is fantastic and works like a dream.
I had code in place that was working, but it was sluggish and fell over
occasionally.
Yours doesn't!
Cheers!
Sarah
-----Original Message-----
From: Michael.Stalford [mailto:michael.stalford@c...]
Sent: 19 March 2003 14:32
To: Access
Subject: [access] Re: File List Box
Sarah,
I just finished writing some code to do this about 10 minutes
ago. Here you go. There is a list box on the form called lstFiles
Private Sub Form_Open(Cancel As Integer)
Dim intCount As Integer
Dim strFileName As String
'Set the initial Path.
'This should be changed to a supporting directory where
'the txt files reside.
strFileName = Dir("e:\My Documents\") ' Retrieve the first entry.
'Start looping through the directory
'We continue looping through until we
'run out of files in the directory
Do While strFileName <> ""
'Using the string function we can check to see if the
'extension matches what we are looking for.
If UCase(Right(strFileName, 4)) = ".txt" Then
'Since it matches, we add it
'to our list box
Me.lstFiles.AddItem strFileName
End If
'Get the next file in the list
strFileName = Dir ' Get next entry.
Loop
End Sub
HTH,
Mike
-----Original Message-----
From: ROBERTS, Sarah [mailto:Sarah.ROBERTS@w...]
Sent: Thursday, March 13, 2003 1:48 AM
To: Access
Subject: [access] Re: File List Box
Wesley
Basically, I want to display the contents of a folder on an Access Form.
So far, we haven't found a way to do this, so are looking at ways around
it.
The windows file selector may well help. If you could explain how to
invoke
this, we could try it out.
Many Thanks
Sarah
-----Original Message-----
From: Wesley Kendrick [mailto:wes@f...]
Sent: 12 March 2003 23:17
To: Access
Subject: [access] Re: File List Box
Hello Sarah
I'm not sure what you mean but if its the Windows file selector you want
I
can tell you how to invoke that.
Regards, Wesley Kendrick
----- Original Message -----
From: "ROBERTS, Sarah" <Sarah.ROBERTS@w...>
To: "Access" <access@p...>
Sent: Tuesday, March 11, 2003 11:39 AM
Subject: [access] File List Box
> All,
>
> I am fairly new to Access and am currently developing a database in
Access
> 2000 at work.
>
> I have hit a problem fairly early on and was hoping that someone from
the
> list can help me out....
>
> In VB, there is a filelistbox function that can be used to diplay the
> contents of a directory folder on a form.
>
> I need to be able to do this on a form in Access 2000, but have hit a
brick
> wall.
>
> Any ideas?
>
> Thanks in advance for any help,
>
> Sarah
>
>
> _________________________________________________________
> This email is confidential and intended solely for the use of the
> individual to whom it is addressed. Any views or opinions presented
are
> solely those of the author and do not necessarily represent those of
> SchlumbergerSema.
> If you are not the intended recipient, be advised that you have
received
> this email in error and that any use, dissemination, forwarding,
printing,
> or copying of this email is strictly prohibited.
>
> If you have received this email in error please notify the
> SchlumbergerSema Helpdesk by telephone on +44 (0) 121 627 5600.
> _________________________________________________________
>
>
>
>
Message #2 by "ROBERTS, Sarah" <Sarah.ROBERTS@w...> on Fri, 21 Mar 2003 12:21:34 +0000
|
|
Excellent.
Thanks for all your help Mike.
-----Original Message-----
From: Michael.Stalford [mailto:michael.stalford@c...]
Sent: 19 March 2003 20:01
To: Access
Subject: [access] Fill a List Box with sorted files
Sarah,
Here is the code that sorts the array and then populates the
list box.
Note that I determine how many items and then populate the
array. This is the Microsoft recommended way for using a dynamic array.
You might find people who combine the first loop with populating the
array. I was told that is not the preferred method. Hope you find it
useful....Mike
Private Sub Form_Open(Cancel As Integer)
Dim intCount As Integer
Dim strFileName As String
Dim astrFiles() As String
Dim intFirstCount As Integer
Dim intSecondCount As Integer
Dim strTemp As String
'Set the initial Path. This should be changed to a supporting
directory where
'the txt files reside.
strFileName = Dir("e:\My Documents\") ' Retrieve the first entry.
'Start looping through the directory
'We continue looping through until we
'run out of files in the directory
Do While strFileName <> ""
'Using the string function we can check to see if the
'extension matches what we are looking for.
If Right(strFileName, 4) = ".xml" Then
'We need to findout how many files there are
intCount = intCount + 1
End If
'Get the next file in the list
strFileName = Dir ' Get next entry.
Loop
'Let's make sure there are files.
'If not, then we tell the user and exit
If intCount = 0 Then
MsgBox "There are no Employee Files to import."
Cancel = True
End If
'Redim the dynamic array with the value determined above
'Since arrays are zero based we need to subtract 1.
ReDim astrFiles(intCount - 1)
'Reset the variables
strFileName = Dir("e:\My Documents\")
intCount = 0
'Loop through looking for files again
Do While strFileName <> ""
'Find the matching file
If Right(strFileName, 4) = ".xml" Then
'Put the file name in the array
astrFiles(intCount) = strFileName
'Increment the counter
intCount = intCount + 1
End If
'Get the next file in the list
strFileName = Dir
Loop
'Sort the file names in the array
'This is a simple bubble sort routine
For intFirstCount = 0 To UBound(astrFiles) - 1
For intSecondCount = 0 To intFirstCount
If LCase(astrFiles(intSecondCount)) >
LCase(astrFiles(intSecondCount + 1)) Then
strTempName = astrFiles(intSecondCount + 1)
astrFiles(intSecondCount) = astrFiles(intSecondCount +
1)
astrFiles(intSecondCount + 1) = strTempName
End If
Next
Next
'Populate the list box in sorted order
For intFirstCount = 0 To UBound(astrFiles) - 1
Me.lstFiles.AddItem astrFiles(intFirstCount)
Next
End Sub
-----Original Message-----
From: ROBERTS, Sarah [mailto:Sarah.ROBERTS@w...]
Sent: Wednesday, March 19, 2003 9:56 AM
To: Access
Subject: [access] Re: File List Box
Yes, i would be interested to see it...
I have extended it slightly to pick up all files in the directory (not
just
.txt) and then on_click to open up the file using shell execute.
Sorted would be good though!
Many thanks Mike
-----Original Message-----
From: Michael.Stalford [mailto:michael.stalford@c...]
Sent: 19 March 2003 15:09
To: Access
Subject: [access] Re: File List Box
Sarah,
I am working on fine tuning it a little. I'll be adding them to
a dynamic array and then sorting the files before adding them to the
list box. Let me know if you would like that as well.
Mike
-----Original Message-----
From: ROBERTS, Sarah [mailto:Sarah.ROBERTS@w...]
Sent: Wednesday, March 19, 2003 9:03 AM
To: Access
Subject: [access] Re: File List Box
Michael
This is fantastic and works like a dream.
I had code in place that was working, but it was sluggish and fell over
occasionally.
Yours doesn't!
Cheers!
Sarah
-----Original Message-----
From: Michael.Stalford [mailto:michael.stalford@c...]
Sent: 19 March 2003 14:32
To: Access
Subject: [access] Re: File List Box
Sarah,
I just finished writing some code to do this about 10 minutes
ago. Here you go. There is a list box on the form called lstFiles
Private Sub Form_Open(Cancel As Integer)
Dim intCount As Integer
Dim strFileName As String
'Set the initial Path.
'This should be changed to a supporting directory where
'the txt files reside.
strFileName = Dir("e:\My Documents\") ' Retrieve the first entry.
'Start looping through the directory
'We continue looping through until we
'run out of files in the directory
Do While strFileName <> ""
'Using the string function we can check to see if the
'extension matches what we are looking for.
If UCase(Right(strFileName, 4)) = ".txt" Then
'Since it matches, we add it
'to our list box
Me.lstFiles.AddItem strFileName
End If
'Get the next file in the list
strFileName = Dir ' Get next entry.
Loop
End Sub
HTH,
Mike
-----Original Message-----
From: ROBERTS, Sarah [mailto:Sarah.ROBERTS@w...]
Sent: Thursday, March 13, 2003 1:48 AM
To: Access
Subject: [access] Re: File List Box
Wesley
Basically, I want to display the contents of a folder on an Access Form.
So far, we haven't found a way to do this, so are looking at ways around
it.
The windows file selector may well help. If you could explain how to
invoke
this, we could try it out.
Many Thanks
Sarah
-----Original Message-----
From: Wesley Kendrick [mailto:wes@f...]
Sent: 12 March 2003 23:17
To: Access
Subject: [access] Re: File List Box
Hello Sarah
I'm not sure what you mean but if its the Windows file selector you want
I
can tell you how to invoke that.
Regards, Wesley Kendrick
----- Original Message -----
From: "ROBERTS, Sarah" <Sarah.ROBERTS@w...>
To: "Access" <access@p...>
Sent: Tuesday, March 11, 2003 11:39 AM
Subject: [access] File List Box
> All,
>
> I am fairly new to Access and am currently developing a database in
Access
> 2000 at work.
>
> I have hit a problem fairly early on and was hoping that someone from
the
> list can help me out....
>
> In VB, there is a filelistbox function that can be used to diplay the
> contents of a directory folder on a form.
>
> I need to be able to do this on a form in Access 2000, but have hit a
brick
> wall.
>
> Any ideas?
>
> Thanks in advance for any help,
>
> Sarah
>
>
> _________________________________________________________
> This email is confidential and intended solely for the use of the
> individual to whom it is addressed. Any views or opinions presented
are
> solely those of the author and do not necessarily represent those of
> SchlumbergerSema.
> If you are not the intended recipient, be advised that you have
received
> this email in error and that any use, dissemination, forwarding,
printing,
> or copying of this email is strictly prohibited.
>
> If you have received this email in error please notify the
> SchlumbergerSema Helpdesk by telephone on +44 (0) 121 627 5600.
> _________________________________________________________
>
>
>
>
|
|
 |