UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Opening File Explorer And Searching In Specific File Pathing, Access 2016    
 
   
Jdk412
post Sep 9 2019, 08:27 AM
Post#1



Posts: 91
Joined: 16-July 18
From: Detroit, MI


Good Morning,

I am trying to make it possible to be able to double click a part number in my database and it will open a file on my server that contains all of the parts information. I am able to get this running fine but I run into issues due to the naming conventions being different for each of our individual customers.


How would I rewrite this code to search for the part number instead of trying to go into the folder?


CODE
Dim shell As Object
Dim sfile As String
sfile = "S:\(Operations)\Customers\" & Me.Customer & "\" & Me.Part_Number
Set shell = CreateObject("WScript.Shell")
shell.run CHr(34) & sfile & CHr(34), 1, False


Thanks
Go to the top of the page
 
ADezii
post Sep 9 2019, 09:24 AM
Post#2



Posts: 2,674
Joined: 4-February 07
From: USA, Florida, Delray Beach


Here is some Sample Code that will search for a File Name that has a Part Number (XYZ123) within it for a Customer named Fred in a Base Folder of C:\Test\. Simply change the Value of strBasePath to suit your specific needs. If the Part Number is contained anywhere within the File Name, a Message Box will appear indicating so, if not, the Message Box will display a File Not Found.
Attached File(s)
Attached File  Found.JPG ( 18.83K )Number of downloads: 1
Attached File  Not_Found.JPG ( 19.08K )Number of downloads: 1
 
Go to the top of the page
 
Jdk412
post Sep 9 2019, 09:26 AM
Post#3



Posts: 91
Joined: 16-July 18
From: Detroit, MI


Thank you for the response. Did you post any code?
Go to the top of the page
 
ADezii
post Sep 9 2019, 09:55 AM
Post#4



Posts: 2,674
Joined: 4-February 07
From: USA, Florida, Delray Beach


Sorry about that, I forgot to include one little detail! iconfused.gif
CODE
Dim strBasePath As String
Dim strCustomer As String
Dim strPartNum As String
Dim strFile As String

strBasePath = "C:\Test\"
strCustomer = "Fred"
strPartNum = "XYZ1r23"

strFile = Dir(strBasePath & strCustomer & "\", vbNormal)

Do While strFile <> ""
  If InStr(strFile, strPartNum) > 0 Then
    MsgBox strBasePath & strCustomer & "\" & strFile, vbInformation, "File Found"
      Exit Sub
  End If
    strFile = Dir()
Loop

'If you get to this point, then no File was found containing the Part Number
MsgBox "No File was found in " & strBasePath & strCustomer & "\ with a Part Number of [" & _
        strPartNum & "]!", vbExclamation, "No File Found"

This post has been edited by ADezii: Sep 9 2019, 09:56 AM
Go to the top of the page
 
Jdk412
post Sep 9 2019, 10:06 AM
Post#5



Posts: 91
Joined: 16-July 18
From: Detroit, MI


So when running this code

I am looking for partnumber: 64328

Actual File Name: 64328, LF Escape Wear Plate

When this code runs it says it cannot find

It seems to ignore file folders and only looks at shortcuts and pdfs (Only other file types in the folder have besides file folders.)

After playing with the code you provided to me i have found the solution, All i had to do was change from VBNormal to vbdirectory

Thank you very much for your help, I would not have been able to achieve this without it.
uarulez2.gif

CODE
On Error GoTo Error

Dim strBasePath As String
Dim strCustomer As String
Dim strPartNum As String
Dim strFile As String

strBasePath = "S:\(Operations)\Customers\"
strCustomer = Me.Customer
strPartNum = Me.PartNumber

strFile = Dir(strBasePath & strCustomer & "\", vbDirectory)

Do While strFile <> ""
  If InStr(strFile, strPartNum) > 0 Then
Application.FollowHyperlink "S:\(Operations)\Customers\" & Me.Customer & "\" & strFile
      Exit Sub
  End If
    strFile = Dir()
Loop

'If you get to this point, then no File was found containing the Part Number
MsgBox "No File was found in " & strBasePath & strCustomer & "\ with a Part Number of [" & _
        strPartNum & "]!", vbExclamation, "No File Found"



GoTo NoError
Error:
MsgBox ("File Not Found")
NoError:


This post has been edited by Jdk412: Sep 9 2019, 10:29 AM
Go to the top of the page
 
ADezii
post Sep 9 2019, 02:12 PM
Post#6



Posts: 2,674
Joined: 4-February 07
From: USA, Florida, Delray Beach


QUOTE
After playing with the code you provided to me i have found the solution, All i had to do was change from VBNormal to vbdirectory

Glad you figured it out, good luck with your Project. thumbup.gif
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    14th October 2019 - 04:02 AM