Re: Display list of files in a folder on a hard drive in a form



Hi,


The following should do, assuming the combo box is pre-set to get its list
from a list of values, and with only one column of data:

=================
Public Sub demoDirTxt()
Dim concat As String
Dim str As String

' find all the files in C:\ with the txt extension
str = Dir("C:\*.txt")

Do While str <> vbNullString

' as long as there are file name found, append them to
' what we have already found
concat = concat & IIf(0 = Len(concat), "", ";") & str

' get the next file, if any
str = Dir()

Loop

' assign the list of values we have just built as the combo box list
Forms!formNameHere!ComboBoxNameHere.RowSource = concat

End Sub
================



Hoping it may help,
Vanderghast, Access MVP

"BLTibbs" <BLTibbs@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AE177B06-8F81-41CB-B5A9-603C0275A7A5@xxxxxxxxxxxxxxxx
>I am too new to code for that to help. I checked the help and couldn't
> figure out how to make it work. What would the code look like?
>
> "Michel Walsh" wrote:
>
>> Hi,
>>
>>
>> Basically you can use the VBA function DIR (see help file for discussion
>> and for an example). You can then recuperate the names in a list box (or
>> combo box) list of values.
>>
>> You can use the file name as if it was an hyperlink to open it.
>>
>>
>> Application.FollowHyperlink "C:\testing.xls"
>>
>>
>>
>> Hoping it may help,
>> Vanderghast, Access MVP
>>
>>
>> "BLTibbs" <BLTibbs@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:45B33E6C-6D1F-41E9-9A24-7EED8C450B52@xxxxxxxxxxxxxxxx
>> >I have searched and cannot find anything on this. How could I create a
>> >form
>> > that searches the contents of a specific folder on a drive on our
>> > network
>> > and
>> > then have it display all of the files located in the folder on a form.
>> > Then
>> > allow the user to select one file at a time to print or view the
>> > document/file in the program that it was created in?
>>
>>
>>


.



Relevant Pages

  • Re: Copy Folder
    ... Vanderghast, Access MVP ... What Code Can I use to copy Folder ...
    (microsoft.public.access.formscoding)
  • Re: copy folder
    ... xcopy. ... Vanderghast, Access MVP ... > What Code Can I use to copy Folder ...
    (microsoft.public.access.formscoding)
  • Re: Copy a folder using vba
    ... "Ken Snell " wrote: ... <MS ACCESS MVP> ... folder to that value that would be pulled from the form and etc, ... To rename a folder or file that already exists, ...
    (microsoft.public.access.modulesdaovba)
  • Re: Cant get Access to run a query with a time field
    ... Since the user enters an exact value, why isn't it saved to the ... Second, a date time value is a floating point value, ... >> Vanderghast, Access MVP ...
    (microsoft.public.access.queries)
  • Re: Exported Excel File is Incomplete
    ... Browse to a single Folder and Export Data to a new EXCEL File in that Folder ... <MS ACCESS MVP> ... Replace the generic NameOfQuery with the real name of the query. ...
    (microsoft.public.access.externaldata)

Loading