Following is the actual folder I want to open which is located in a server.
\\myserver\My Folder Documents\
I need to open the the documents in this folder.
Open folder with search value
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Open folder with search value
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Open folder with search value
by "yeah" I meant I want the code to open the documents with any extension such as .pdf, .xls, xlsm, .doc that is located in the folder named "My Folder Documents" which is located in a server named as "myserver"
the path for the documents in the folder is as follows
\\myserver\My Folder Documents\
I hope I've made my question clear.
Thanks in advance.
the path for the documents in the folder is as follows
\\myserver\My Folder Documents\
I hope I've made my question clear.
Thanks in advance.
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open folder with search value
In that case, your code is overkill. See if the attached version works for you.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Open folder with search value
Thanks for the help Hans. Where can I place a message in the existing code where ehen the user searches a document or text that is not available in the folder it gives a message saying the document is not available.
Any help would be kindly appreciated.
Any help would be kindly appreciated.
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open folder with search value
Change CommandButton3_Click as follows:
Code: Select all
Private Sub CommandButton3_Click()
Dim FileFilter As String
Dim MyFile As String
FileFilter = Me.SearchTextBox
If FileFilter = "" Then
Me.SearchTextBox.SetFocus
MsgBox "Please enter a search text, then try again.", vbInformation
Exit Sub
End If
Me.ListBox1.Clear
FileFilter = "*" & FileFilter & "*"
MyFile = Dir(MyPath & FileFilter)
Do While MyFile <> ""
Me.ListBox1.AddItem MyFile
MyFile = Dir
Loop
If Me.ListBox1.ListCount = 0 Then
MsgBox "There are no files matching the search text!", vbInformation
End If
End Sub
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Open folder with search value
I've added a second textbox txt.date.value to my userform.
The purpose of this is to allow the user to search folder items by date and name.
For example if the user types date 20-06-2022 in textbox txt.date.value and file name apples in Me.SearchTextBox, I want the code to filter the file with that particular name and date.
How may I achieve this?
The purpose of this is to allow the user to search folder items by date and name.
For example if the user types date 20-06-2022 in textbox txt.date.value and file name apples in Me.SearchTextBox, I want the code to filter the file with that particular name and date.
How may I achieve this?
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open folder with search value
I am away from my computer at the moment. If nobody else replies, I will look at it later.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open folder with search value
I'll use txtDate as name of the text box, for txt.date is not a valid name for a text box: point is not allowed.
Try this:
Try this:
Code: Select all
Private Sub CommandButton3_Click()
Dim FileFilter As String
Dim MyFile As String
FileFilter = Me.SearchTextBox
If FileFilter = "" Then
Me.SearchTextBox.SetFocus
MsgBox "Please enter a search text, then try again.", vbInformation
Exit Sub
End If
Me.ListBox1.Clear
FileFilter = "*" & FileFilter & "*"
MyFile = Dir(MyPath & FileFilter)
Do While MyFile <> ""
If Int(FileDateTime(MyPath & FileFilter)) = CLng(Me.txtDate) Then
Me.ListBox1.AddItem MyFile
End If
MyFile = Dir
Loop
If Me.ListBox1.ListCount = 0 Then
MsgBox "There are no files matching the search text!", vbInformation
End If
End Sub
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07