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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Wildcard in a File Name in VBA 1

Status
Not open for further replies.

kopy

Technical User
May 30, 2002
141
US
Hi, I'm trying to open a jpeg using a wildcard in the file name. I constructed the filename in a variable called Draft. At this point the code doesn't find a file and abviously I've either tried to do something that can't be done or have made a syntaxt mistake I don't understand. Any help will be greatly appreciated. Thanks, Kopy
-----------------------------------------------------------
Dim oApp As Object
Dim picPath As String, Draft As String, Pic As String

picPath = "C:\Impact Consulting\Computer Care Associates\H G Cockrill\Drawings\"

Draft = Me.[txtPart#] & "*" & ".jpg"

If Dir(picPath & Draft, vbNormal) <> "" Then
Pic = picPath & Draft
Application.FollowHyperlink Pic, , True
Else
MsgBox "No Drawing Currently on File"
End If
 
You would need to use the file returned by Dir:

[tt]strFile= Dir(picPath & Draft, vbNormal)
If Trim(strFile & "") <> "" Then
Pic = picPath & strFile[/tt]

There more be more than one file returned. You can check for these by using Dir again.
 
Thanks for the help, Kopy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top