Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcard in a filename.

Status
Not open for further replies.

PALman

Technical User
May 15, 2002
160
GB
I have been looking through the posts for info on wildcards within a file name.
I have a number of documents (Excel,Word and PDF files)which I need to open from a command button.
They all have one thing in common in that they are named with firstly a Job Number followed by a hyphen and after that a unique combination of alphanumeric charachters. So I have something like this...
JobNo = textbox(11).txt
Filename = JobNo & "-" & "PO452345.PDF"
or
Filename = JobNo & "-" & "MPI.xls"
I just cannot get the syntax correct for a wild card (%) to replace the part after the "-"
Most of what I have read here uses LIKE but I wonder if it is necessary in this simple file name.
Any help would be much appreciated.
 
Thanks Bob,
In the unlikely event of there being more than one file which fits the crierea then I would wish to manually select from the list.
Thanks.
 
Very good. So, maybe a good way to go is to use a dirlistbox and filelistbox control. To demonstrate a basic use of them, just put a dirlistbox, a drivelistbox, a filelistbox and a text box on a form. Then add the following code:
Code:
Option Explicit

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub File1_DblClick()
MsgBox File1.List(File1.ListIndex)
End Sub

Private Sub Text1_Change()
File1.Pattern = Text1.Text
End Sub
This should give you the basics of what you're looking for. (You may not need the drivelistbox, but I included it to demonstrate it.) You should be able to decorate it on your own.

HTH

Bob
 
Thanks Bob,
I have done as you suggested and looked at your coding and have saved it for use later.
However just before I read your reply I had been working through the Dir() function and wildcards and I managed to get everything up and running.
I have posted my updated code here. It allows me to enter a record of an Access Table and based on the Job Number (Key field) I can now with one click of the mouse pull down a menu which lists Customer Documentation for that Job Number
and a second click on Purchase Order automatically loads up the PO (an adobe file).
The line...
adobeFile = Dir(Path & "*PO*") 'for any occurence of PO.
allows the file to be named in any way as long as it has PO included. This then would load up any file with PO in its name, including an earlier revision of the current PO. There would be no other files with PO in the filename. Other files in the same Job Folder would be named with the words/letters such as BOM (Bill of Materials) DWG (Drawings) QPLAN (Quality Plans) and SPECS (Specifications).
However although I am going to use the same code for each of the files It would be nice to incorporate your code to give a choice just in case files with these names within their filename start making an appearance.
The code as it stands at the moment...

Private Sub mnuPO_Click()
'Pulldown Menu for Purchase Order
Dim Path As String, JobNo As String, adobeFile As String

JobNo = txtFields(11).Text
Path = "C:\000-QualityControlProgram\JobsFolder\" & JobNo & "\"

'adobeFile = Dir(Path & "PO*.*") 'for filename beginning with PO.
adobeFile = Dir(Path & "*PO*") 'for any occurence of PO.

Do While adobeFile <> ""
'Debug.Print adobeFile

'Requires reference to Microsoft Scripting Runtime to use the FileSystemObject.
With New FileSystemObject
If .FileExists(Path & adobeFile) Then
ExecuteWait Path & adobeFile
Else
MsgBox "File " & Path & adobeFile & " does not exist."
End If
End With

adobeFile = Dir()
Loop

End Sub

I shall continue to develop and improve by working with the code you have kindly posted.
Thanks again.
 
Just so you know, I spent all of 10 minutes putting that together. It's quite simple to use. Good luck! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top