On 06 Jul 2004 16:56:48 GMT, jason mckinney <jw*****@yahoo.com> wrote:
Hi Jim,
Thanks for your fast reply. I have limited experience with Access and
its been several years since I've touched VB and have never used VBA
with Access so I'm having a little trouble following you. If you could
dumb this down for me any more than you have then I would greatly
appreciate it. Also I have multiple folders that I have to look in to
generate my list. This is going to save me a week's worth of typing if I
can get it to work quickly. Thanks a lot!
Jason
Hi Jason,
To get this to work copy the function and paste it into a standard
module.
Select the modules tab on the DB window, click New and paste it. Save
it as something other than the name of the function - maybe "basDir" .
To use the function supply it with the path of the folder like..
fFilesInDir("C:\FolderName\")
If you had a folder on your C: drive named "FolderName" then you would
get back the semi-colon delimited list.
You can test this in the debug window. Press <Ctrl><g> to open it and
then type:
?fFilesInDir("A_Path_To_A_Folder")
Then press <Enter>
Note that the semi-colon list is set to be used as a RowSource of a
List box or Combo box on a form. For example to use it as the
RowSource of a List Box; create a new listbox on a form (lets call it
"lstTest"), open the properties window for it, select the Data tab and
set Row Source Type to "Value List". Now in the properties for the
form click the Event tab and select the On Open event, click the
ellipsis button to the right [...], open the forms module to the open
event type in like...
Private Sub Form_Open(Cancel As Integer)
Me.lstTest.RowSource = fFilesInDir("C:\MyFolder\")
End Sub
Now to test this a different way you could change the code to printout
to the debug window the files. Change it to...
========================
Public Function fFilesInDir(strDir As String) As String
Dim strListSrce As String
Dim strFile As String
strListSrce = Dir(strDir & "*.*")
Debug.Print strListSrce
If Len(strListSrce) = 0 Then
MsgBox "Empty directory!"
Exit Function
End If
Do
strFile = Dir
If Len(strFile) = 0 Then
Exit Do
Else
strListSrce = strListSrce & ";" & strFile
Debug.Print strFile
End If
Loop
fFilesInDir = strListSrce
End Function
====================
Depending on what you want to do; the code could be altered some more.
- Jim