Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 19th, 2006, 11:55 AM
sam
Guest
 
Posts: n/a
Default how to use items in a list as a hyperlink

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

  #2  
Old December 19th, 2006, 02:15 PM
Tom van Stiphout
Guest
 
Posts: n/a
Default Re: how to use items in a list as a hyperlink

On 19 Dec 2006 03:54:34 -0800, "sam" <sameersrivastava2k@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.


Quote:
>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
  #3  
Old December 20th, 2006, 12:25 PM
sam
Guest
 
Posts: n/a
Default Re: how to use items in a list as a hyperlink

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:
Quote:
On 19 Dec 2006 03:54:34 -0800, "sam" <sameersrivastava2k@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.
>
>
>
Quote:
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
  #4  
Old December 20th, 2006, 01:55 PM
Tom van Stiphout
Guest
 
Posts: n/a
Default Re: how to use items in a list as a hyperlink

On 20 Dec 2006 04:23:36 -0800, "sam" <sameersrivastava2k@gmail.com>
wrote:

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

Quote:
>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:
>
Quote:
>On 19 Dec 2006 03:54:34 -0800, "sam" <sameersrivastava2k@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.
>>
>>
>>
Quote:
>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
  #5  
Old December 20th, 2006, 04:35 PM
sam
Guest
 
Posts: n/a
Default Re: how to use items in a list as a hyperlink

i am also using access 2003
i will just check may be i am making another mistake
reply you tomorrow

Tom van Stiphout wrote:
Quote:
On 20 Dec 2006 04:23:36 -0800, "sam" <sameersrivastava2k@gmail.com>
wrote:
>
Mine was unbound as well. I was using Access 2003. You?
-Tom.
>
>
Quote:
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:
Quote:
On 19 Dec 2006 03:54:34 -0800, "sam" <sameersrivastava2k@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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles