By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

how to use items in a list as a hyperlink

P: n/a
sam
Hi all,

Kindly have a look to the code given below
************************************************** ***************************
Public Function CountFiles(strDir As String, Optional SubDir As
Boolean) As Long

With Application.FileSearch
.NewSearch
.LookIn = strDir
.FileName = "*.*"
.SearchSubFolders = SubDir
If .Execute 0 Then
CountFiles = .FoundFiles.count
End If

For i = 1 To .FoundFiles.count
Me.list1.AddItem (.FoundFiles(i))
Next i

End With
End Function
************************************************** **********************
you must have understood that this code is helping me to count the
number of files in a given folder and adding the names of those files
in a listbox.
It is adding the file name in the list box as
"I:\folder1\subfolder1\file1.doc"
but i want the name to be added in the list box as "file1.doc"

My second question is , is it possible to open the same file in the
list box by double clicking the filename.

can any one give me the solution for the problem.

sam

Dec 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 19 Dec 2006 03:54:34 -0800, "sam" <sa****************@gmail.com>
wrote:

I think the FileSearch object is a bit limited. Here is similar code
using the more powerful FileSystemObject:

Private Function fsoCountFiles(ByVal strDir As String)
Dim fso As Scripting.FileSystemObject
Dim folder As Scripting.folder
Dim file As Scripting.file

Set fso = New Scripting.FileSystemObject
Set folder = fso.GetFolder(strDir)
For Each file In folder.Files
Me.List4.AddItem (file.Name)
Next file
Set file = Nothing
Set folder = Nothing
Set fso = Nothing
End Function

Then the double-click event:
Private Sub List4_DblClick(Cancel As Integer)
Dim strFullName As String
'Text0 has the root for the search.
strFullName = Me.Text0.Value & "\" &
List4.ItemData(List4.ListIndex)
Application.FollowHyperlink strFullName
End Sub

-Tom.
>Hi all,

Kindly have a look to the code given below
************************************************* ****************************
Public Function CountFiles(strDir As String, Optional SubDir As
Boolean) As Long

With Application.FileSearch
.NewSearch
.LookIn = strDir
.FileName = "*.*"
.SearchSubFolders = SubDir
If .Execute 0 Then
CountFiles = .FoundFiles.count
End If

For i = 1 To .FoundFiles.count
Me.list1.AddItem (.FoundFiles(i))
Next i

End With
End Function
************************************************* ***********************
you must have understood that this code is helping me to count the
number of files in a given folder and adding the names of those files
in a listbox.
It is adding the file name in the list box as
"I:\folder1\subfolder1\file1.doc"
but i want the name to be added in the list box as "file1.doc"

My second question is , is it possible to open the same file in the
list box by double clicking the filename.

can any one give me the solution for the problem.

sam
Dec 19 '06 #2

P: n/a
sam
Thanks tom

when i am running your code it is giving me compile error on this line

List4.ItemData(List4.ListIndex)

for ItemData it says "invalid use of property"

is it because my list box is unbound
the values that are in the list are not bound to any field in the table
these values are just the name of the files in a particular folder
i just want to open these files on double click

is there any solution to this problem

sam
Tom van Stiphout wrote:
On 19 Dec 2006 03:54:34 -0800, "sam" <sa****************@gmail.com>
wrote:

I think the FileSearch object is a bit limited. Here is similar code
using the more powerful FileSystemObject:

Private Function fsoCountFiles(ByVal strDir As String)
Dim fso As Scripting.FileSystemObject
Dim folder As Scripting.folder
Dim file As Scripting.file

Set fso = New Scripting.FileSystemObject
Set folder = fso.GetFolder(strDir)
For Each file In folder.Files
Me.List4.AddItem (file.Name)
Next file
Set file = Nothing
Set folder = Nothing
Set fso = Nothing
End Function

Then the double-click event:
Private Sub List4_DblClick(Cancel As Integer)
Dim strFullName As String
'Text0 has the root for the search.
strFullName = Me.Text0.Value & "\" &
List4.ItemData(List4.ListIndex)
Application.FollowHyperlink strFullName
End Sub

-Tom.
Hi all,

Kindly have a look to the code given below
************************************************** ***************************
Public Function CountFiles(strDir As String, Optional SubDir As
Boolean) As Long

With Application.FileSearch
.NewSearch
.LookIn = strDir
.FileName = "*.*"
.SearchSubFolders = SubDir
If .Execute 0 Then
CountFiles = .FoundFiles.count
End If

For i = 1 To .FoundFiles.count
Me.list1.AddItem (.FoundFiles(i))
Next i

End With
End Function
************************************************** **********************
you must have understood that this code is helping me to count the
number of files in a given folder and adding the names of those files
in a listbox.
It is adding the file name in the list box as
"I:\folder1\subfolder1\file1.doc"
but i want the name to be added in the list box as "file1.doc"

My second question is , is it possible to open the same file in the
list box by double clicking the filename.

can any one give me the solution for the problem.

sam
Dec 20 '06 #3

P: n/a
On 20 Dec 2006 04:23:36 -0800, "sam" <sa****************@gmail.com>
wrote:

Mine was unbound as well. I was using Access 2003. You?
-Tom.

>Thanks tom

when i am running your code it is giving me compile error on this line

List4.ItemData(List4.ListIndex)

for ItemData it says "invalid use of property"

is it because my list box is unbound
the values that are in the list are not bound to any field in the table
these values are just the name of the files in a particular folder
i just want to open these files on double click

is there any solution to this problem

sam
Tom van Stiphout wrote:
>On 19 Dec 2006 03:54:34 -0800, "sam" <sa****************@gmail.com>
wrote:

I think the FileSearch object is a bit limited. Here is similar code
using the more powerful FileSystemObject:

Private Function fsoCountFiles(ByVal strDir As String)
Dim fso As Scripting.FileSystemObject
Dim folder As Scripting.folder
Dim file As Scripting.file

Set fso = New Scripting.FileSystemObject
Set folder = fso.GetFolder(strDir)
For Each file In folder.Files
Me.List4.AddItem (file.Name)
Next file
Set file = Nothing
Set folder = Nothing
Set fso = Nothing
End Function

Then the double-click event:
Private Sub List4_DblClick(Cancel As Integer)
Dim strFullName As String
'Text0 has the root for the search.
strFullName = Me.Text0.Value & "\" &
List4.ItemData(List4.ListIndex)
Application.FollowHyperlink strFullName
End Sub

-Tom.
>Hi all,

Kindly have a look to the code given below
************************************************* ****************************
Public Function CountFiles(strDir As String, Optional SubDir As
Boolean) As Long

With Application.FileSearch
.NewSearch
.LookIn = strDir
.FileName = "*.*"
.SearchSubFolders = SubDir
If .Execute 0 Then
CountFiles = .FoundFiles.count
End If

For i = 1 To .FoundFiles.count
Me.list1.AddItem (.FoundFiles(i))
Next i

End With
End Function
************************************************* ***********************
you must have understood that this code is helping me to count the
number of files in a given folder and adding the names of those files
in a listbox.
It is adding the file name in the list box as
"I:\folder1\subfolder1\file1.doc"
but i want the name to be added in the list box as "file1.doc"

My second question is , is it possible to open the same file in the
list box by double clicking the filename.

can any one give me the solution for the problem.

sam
Dec 20 '06 #4

P: n/a
sam
i am also using access 2003
i will just check may be i am making another mistake
reply you tomorrow

Tom van Stiphout wrote:
On 20 Dec 2006 04:23:36 -0800, "sam" <sa****************@gmail.com>
wrote:

Mine was unbound as well. I was using Access 2003. You?
-Tom.

Thanks tom

when i am running your code it is giving me compile error on this line

List4.ItemData(List4.ListIndex)

for ItemData it says "invalid use of property"

is it because my list box is unbound
the values that are in the list are not bound to any field in the table
these values are just the name of the files in a particular folder
i just want to open these files on double click

is there any solution to this problem

sam
Tom van Stiphout wrote:
On 19 Dec 2006 03:54:34 -0800, "sam" <sa****************@gmail.com>
wrote:

I think the FileSearch object is a bit limited. Here is similar code
using the more powerful FileSystemObject:

Private Function fsoCountFiles(ByVal strDir As String)
Dim fso As Scripting.FileSystemObject
Dim folder As Scripting.folder
Dim file As Scripting.file

Set fso = New Scripting.FileSystemObject
Set folder = fso.GetFolder(strDir)
For Each file In folder.Files
Me.List4.AddItem (file.Name)
Next file
Set file = Nothing
Set folder = Nothing
Set fso = Nothing
End Function

Then the double-click event:
Private Sub List4_DblClick(Cancel As Integer)
Dim strFullName As String
'Text0 has the root for the search.
strFullName = Me.Text0.Value & "\" &
List4.ItemData(List4.ListIndex)
Application.FollowHyperlink strFullName
End Sub

-Tom.

Hi all,

Kindly have a look to the code given below
************************************************** ***************************
Public Function CountFiles(strDir As String, Optional SubDir As
Boolean) As Long

With Application.FileSearch
.NewSearch
.LookIn = strDir
.FileName = "*.*"
.SearchSubFolders = SubDir
If .Execute 0 Then
CountFiles = .FoundFiles.count
End If

For i = 1 To .FoundFiles.count
Me.list1.AddItem (.FoundFiles(i))
Next i

End With
End Function
************************************************** **********************
you must have understood that this code is helping me to count the
number of files in a given folder and adding the names of those files
in a listbox.
It is adding the file name in the list box as
"I:\folder1\subfolder1\file1.doc"
but i want the name to be added in the list box as "file1.doc"

My second question is , is it possible to open the same file in the
list box by double clicking the filename.

can any one give me the solution for the problem.

sam
Dec 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.