List a folders contents from a widows Directory

G

Guest

Hello,

I was wondering if it is possible to have a list box populated with the
contents of a folder in a directory located on a server. The files in the
folder are in PDF. Then on Double Click to open the file.

Is this possible? If so how do I do this.

Thanks

Kyle
 
A

Allen Browne

You can set the RowSourceType of a list box to the a specially crafted
callback function such as this one:
http://allenbrowne.com/func-02.html
Don't use = or brackets. and leave teh RowSource property blank.
In the code, substitute the name of your folder for "C:\".

To open the file with the default PDF hander, use FollowHyperlink in the
DblClick event of the list box.
 
G

Guest

Thank you for helping me with this Allen.

Where do I place the Code? on an event ? if so which one?
I am new with coding.

Thanks
 
G

Guest

How do I set a call back function?

Allen Browne said:
You can set the RowSourceType of a list box to the a specially crafted
callback function such as this one:
http://allenbrowne.com/func-02.html
Don't use = or brackets. and leave teh RowSource property blank.
In the code, substitute the name of your folder for "C:\".

To open the file with the default PDF hander, use FollowHyperlink in the
DblClick event of the list box.
 
A

Allen Browne

1. Click the Modules tab of the database window, and click New.
Access opens the code window.

2. Paste the code in, exactly as it is.
The folder name is all you need to change.

3. To ensure Access understands the code, choose Compile on the Debug menu
(in the code window.) Then save it with a name such as Module1.

4. Set the RowSourceType property of your list box.
Test: it should show the list of files.

5. Once you have that working, set the On DblClick property of the list box
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

6. Between the "Private Sub..." and "End Sub lines, enter:
If Not IsNull(Me.[List0] Then
FollowHyperlink Me.[List0]
End If
replacing the "List0" with the name of your listbox.
 
G

Guest

Allen I get an expected end of statment error: here is my code Changing the
directory path:
Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$ "\\aticorfs01\users\kphillips\My
Documents\Flood" ' Read filespec from a form here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1
 
A

Allen Browne

The line wrapped wrongly, but I am guessing that was just the post.

Did you include the brackets around the path name?
 
G

Guest

Okay, the module compiles with no messages so I am assuming it is okay now. I
did include the brackets. Now I get the message "DirListBox" may not be a
valid RowSourceType property, or there was a compile error in the function.
 
A

Allen Browne

Did you just type:
DirListBox
straight into the RowSourceType property of the list box, after saving the
function in the general module?

Not equal sign. No brackets.

This should work in any version of Access.
 
G

Guest

Allen you are good my man.

Thanks.

I just redid the whole thing in a test Dbase. I started by creating the
module first and then the list box 2nd and it worked.

Thanks for your time and your help. Very much appreciated.

Cheers
 
G

Guest

Hi Allen sorry to be a bother.

How do I open the file through the list box? I cannot find the
FollowHyperlink as suggested.

Thanks

K
 
G

Guest

Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
 
G

Guest

Hi Allen one last thing. The list shows all files in the DIrectory but I can
not seem to make it point to a specific folder and read the contents of it.
Here is the code. Can you help me on that. P: is the drive. Public within the
company. The folder I want it to show the files within is called Flood.

Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1

K said:
Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
Allen Browne said:
Go back to the 2nd reply I gave you, and pick up at step 5.
 
A

Allen Browne

Perhaps something like this:
StrFileName = Dir$("P:\MyFolder\*.pdf")

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

K said:
Hi Allen one last thing. The list shows all files in the DIrectory but I
can
not seem to make it point to a specific folder and read the contents of
it.
Here is the code. Can you help me on that. P: is the drive. Public within
the
company. The folder I want it to show the files within is called Flood.

Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1

K said:
Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
Allen Browne said:
Go back to the 2nd reply I gave you, and pick up at step 5.

Hi Allen sorry to be a bother.

How do I open the file through the list box? I cannot find the
FollowHyperlink as suggested.
 
G

Guest

Hi Allen,

Now I get this message

Run-time Error 9 - Subscript out of range.
Code looks like this:

Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir$("P:\it\*.pdf")

IntCount = IntCount + 1

Allen Browne said:
Perhaps something like this:
StrFileName = Dir$("P:\MyFolder\*.pdf")

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

K said:
Hi Allen one last thing. The list shows all files in the DIrectory but I
can
not seem to make it point to a specific folder and read the contents of
it.
Here is the code. Can you help me on that. P: is the drive. Public within
the
company. The folder I want it to show the files within is called Flood.

Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1

K said:
Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
:

Go back to the 2nd reply I gave you, and pick up at step 5.

Hi Allen sorry to be a bother.

How do I open the file through the list box? I cannot find the
FollowHyperlink as suggested.
 
A

Allen Browne

Which line gives the error?

Could there be more than 512 files in your folder? If so, increase the 511
in the static array definition at the top of the procedure.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

K said:
Hi Allen,

Now I get this message

Run-time Error 9 - Subscript out of range.
Code looks like this:

Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir$("P:\it\*.pdf")

IntCount = IntCount + 1

Allen Browne said:
Perhaps something like this:
StrFileName = Dir$("P:\MyFolder\*.pdf")

K said:
Hi Allen one last thing. The list shows all files in the DIrectory but
I
can
not seem to make it point to a specific folder and read the contents of
it.
Here is the code. Can you help me on that. P: is the drive. Public
within
the
company. The folder I want it to show the files within is called Flood.

Case 1 ' Open: load file names into
array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form
here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1

:

Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
:

Go back to the 2nd reply I gave you, and pick up at step 5.

Hi Allen sorry to be a bother.

How do I open the file through the list box? I cannot find the
FollowHyperlink as suggested.
 
G

Guest

This line is Yellow with an arrow deside it

StrFiles(IntCount) = StrFileName

There is only one PDF file in the folder on the P Directory and the Folder
is called "IT"

When I Debug the error and place my cursor over the yellow line it does show
the correct PDF file which states : StrFileName = "the PDF File"

I have tried increasing the Static to 999 But I still get the same error.

Allen Browne said:
Which line gives the error?

Could there be more than 512 files in your folder? If so, increase the 511
in the static array definition at the top of the procedure.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

K said:
Hi Allen,

Now I get this message

Run-time Error 9 - Subscript out of range.
Code looks like this:

Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir$("P:\it\*.pdf")

IntCount = IntCount + 1

Allen Browne said:
Perhaps something like this:
StrFileName = Dir$("P:\MyFolder\*.pdf")

Hi Allen one last thing. The list shows all files in the DIrectory but
I
can
not seem to make it point to a specific folder and read the contents of
it.
Here is the code. Can you help me on that. P: is the drive. Public
within
the
company. The folder I want it to show the files within is called Flood.

Case 1 ' Open: load file names into
array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form
here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1

:

Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
:

Go back to the 2nd reply I gave you, and pick up at step 5.

Hi Allen sorry to be a bother.

How do I open the file through the list box? I cannot find the
FollowHyperlink as suggested.
 
A

Allen Browne

Ask Access for the value of intCount.
It must be a number between 0 and the maximum number.
(That's what 'out of range' suggests is wrong.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

K said:
This line is Yellow with an arrow deside it

StrFiles(IntCount) = StrFileName

There is only one PDF file in the folder on the P Directory and the Folder
is called "IT"

When I Debug the error and place my cursor over the yellow line it does
show
the correct PDF file which states : StrFileName = "the PDF File"

I have tried increasing the Static to 999 But I still get the same error.

Allen Browne said:
Which line gives the error?

Could there be more than 512 files in your folder? If so, increase the
511
in the static array definition at the top of the procedure.

K said:
Hi Allen,

Now I get this message

Run-time Error 9 - Subscript out of range.
Code looks like this:

Case 1 ' Open: load file names into
array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form
here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir$("P:\it\*.pdf")

IntCount = IntCount + 1

:

Perhaps something like this:
StrFileName = Dir$("P:\MyFolder\*.pdf")

Hi Allen one last thing. The list shows all files in the DIrectory
but
I
can
not seem to make it point to a specific folder and read the contents
of
it.
Here is the code. Can you help me on that. P: is the drive. Public
within
the
company. The folder I want it to show the files within is called
Flood.

Case 1 ' Open: load file names into
array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form
here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1

:

Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
:

Go back to the 2nd reply I gave you, and pick up at step 5.
 
G

Guest

Sorry Allen,

You must think I am new or something. I apreciate you taking the time to
guide me through this.

How do I ask Access for the Value of intCount

Allen Browne said:
Ask Access for the value of intCount.
It must be a number between 0 and the maximum number.
(That's what 'out of range' suggests is wrong.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

K said:
This line is Yellow with an arrow deside it

StrFiles(IntCount) = StrFileName

There is only one PDF file in the folder on the P Directory and the Folder
is called "IT"

When I Debug the error and place my cursor over the yellow line it does
show
the correct PDF file which states : StrFileName = "the PDF File"

I have tried increasing the Static to 999 But I still get the same error.

Allen Browne said:
Which line gives the error?

Could there be more than 512 files in your folder? If so, increase the
511
in the static array definition at the top of the procedure.

Hi Allen,

Now I get this message

Run-time Error 9 - Subscript out of range.
Code looks like this:

Case 1 ' Open: load file names into
array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form
here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir$("P:\it\*.pdf")

IntCount = IntCount + 1

:

Perhaps something like this:
StrFileName = Dir$("P:\MyFolder\*.pdf")

Hi Allen one last thing. The list shows all files in the DIrectory
but
I
can
not seem to make it point to a specific folder and read the contents
of
it.
Here is the code. Can you help me on that. P: is the drive. Public
within
the
company. The folder I want it to show the files within is called
Flood.

Case 1 ' Open: load file names into
array
DirListBox = Timer
StrFileName = Dir$("P:\") ' Read filespec from a form
here???
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1

:

Hi Allen,

Thanks, Sorry I missed that comment.

I now get a run-time error 490 cannot open specified file.

Here is my code:
Private Sub List0_DblClick(Cancel As Integer)
If Not IsNull(Me.[List0]) Then
FollowHyperlink Me.[List0]
End If

End Sub
:

Go back to the 2nd reply I gave you, and pick up at step 5.
 

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