473,395 Members | 1,706 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,395 software developers and data experts.

File List Creator

Is there a way to have Access look inside a folder or folders and with
a query create a list of files within these folders? Thanks in advance
Nov 13 '05 #1
5 7113
On 6 Jul 2004 05:33:58 -0700, jw*****@yahoo.com (jwmckin) wrote:
Is there a way to have Access look inside a folder or folders and with
a query create a list of files within these folders? Thanks in advance


Not in a query directly. They would have to be in a table to query
them. However, you could get a list with a function. The following
function will return a list separated by semi-colons ready for a
listbox or combobox rowsource.

==========================
Public Function fFilesInDir(strDir As String) As String
'The input string strDir needs to be structured like:
'C:\MyFolder\
'Depending on your usage you might need to manage this.

Dim strListSrce As String
Dim strFile As String

strListSrce = Dir(strDir & "*.*")
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
End If
Loop
fFilesInDir = strListSrce

End Function
==========================

- Jim

Nov 13 '05 #2
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

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
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
Nov 13 '05 #4
I tried that and I'm getting these compile errors...

Code
Public Function fFilesInDir(C:\Documents and Settings) As String

Error
Expected: list seperator or )

It seems to have problems with the semicolon in C:\

What could be the issue here?

I've also tried

Code
Public Function fFilesInDir("C:\Documents and Settings") As String

Public Function fFilesInDir("C:\Documents and Settings" as String) As
String

Public Function fFilesInDir(strDir "C:\Documents and Settings" as
String) As String
Thanks again!

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
On 06 Jul 2004 20:16:32 GMT, jason mckinney <jw*****@yahoo.com> wrote:
I tried that and I'm getting these compile errors...

Code
Public Function fFilesInDir(C:\Documents and Settings) As String

Error
Expected: list seperator or )

It seems to have problems with the semicolon in C:\

What could be the issue here?

I've also tried

Code
Public Function fFilesInDir("C:\Documents and Settings") As String

Public Function fFilesInDir("C:\Documents and Settings" as String) As
String

Public Function fFilesInDir(strDir "C:\Documents and Settings" as
String) As String
Thanks again!

I'm a little confused on what you are doing here.
Did you copy the entire function - the lines between the ==========='s
and paste into a a new module and save the module? If you copied and
pasted it properly then it should compile.

If so then test it from the debug window.

? fFilesInDir("C:\Documents and Settings\")

Put that in and press <Enter>

Also, note the back slash at the end of the path argument. That's all
you need,
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Suzie | last post by:
Hello, I'm only new at this so please bear with me! I am creating an ontology for a color game and i am using the pizza tutorial as a basis for it. I did everything and when I went to save the...
1
by: Stefan Ram | last post by:
Some style guides suggest to repeat a DC.creator meta-element for multiple authors, but doesn't this contradict its specification? "An entity primarily responsible for making the content of the...
3
by: brckcc | last post by:
I'm attempting to use XmlTextReader. When I call the Read() method I get the following error "The data at the root level is invalid. Line 1, position 1. The xml is formatted fine. The first...
1
by: Gorilla | last post by:
I bound my package with EXPLAIN(YES), and it's got the following static SQL in it: EXEC SQL SELECT CARDF, RECLENGTH INTO :CARDF,:RECLENGTH FROM SYSIBM.SYSTABLES WHERE NAME = :TBNAME AND...
4
by: KC Eric | last post by:
Hi all, I have a dll file, it has a class, say: class Temp, this class has a function which has a delegate as a parameter, say: public void Test(GameOverHandler _overHandler)
77
by: Ville Vainio | last post by:
I tried to clear a list today (which I do rather rarely, considering that just doing l = works most of the time) and was shocked, SHOCKED to notice that there is no clear() method. Dicts have it,...
11
by: Kush | last post by:
Hello All, I am having problem writing some data to file and I do not understand my mistake / misconception. I am trying to write some simple text to file but the text is rather output to...
10
by: virtualadepts | last post by:
www.awprofessional.com/series/indepth/ Go here to get the complete book list that the creator of C++ has compiled, along with his book "The C++ Programming Language, Third Edition". Bjarne...
5
by: heday60 | last post by:
I've got this application that watches a directory for XML's and then parses them into a DB. It then moves them based on if the XML was succesful or a bad XML... foreach(FileInfo file in...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.