Full Version: Open file using parital name ?
UtterAccess Forums > Microsoft® Access > Access Forms
XOX
I am trying to create a command button that will open a file. I need it to look at a 9 digit job number on a form and look for a pdf file in a directory with the first 9 characters equaling the job number. This problem is caused by my copier automatically attached a 14 character suffix followed by a .pdf to my 9 character name. so when I enter 050808400 it names the file 050808400_20081006104424.pdf
So what I need help with is how to go to C:\PT\Contracts\ and grab the file by the first 9 characters of the name.
Thanks ahead of time.
strive4peace
do something like this:
!--c1-->
CODE
   dim strPath as string _
      , strMask as string
      , strFilename as string

   strPath = "C:\PT\Contracts\"
  
   if isnull(me.JobNumber_controlname) then
      'job number not filled out -- cannot open file
      exit Sub ' or Function
   end if
   strMask  = strPath & me.JobNumber_controlname & "*.pdf"

   strFilename  = Dir(strMask)

   if len(trim(strFilename  )) > 0 then
      msgbox "The file to open is " & strFilename
   end if

WHERE
JobNumber_controlname is the name of the control on the form this code is behind containing the Job Number
XOX
No luck yet. I got close but when I get close it starts giving me a hyperlink error. Whats strange is if I put in the whole path it opens the pdf file no problem and I have worked out a string that returns the full file name but when I call out Application.FollowHyperlink strFilename which returns the full file name it gives me a hyperlink error and does nothing. Im not sure where to even go from here but I can't tell you how much I would appreciate some help getting through this one.
Thanks for all of your help so far.
strive4peace
CODE
   if len(trim(strFilename  )) > 0 then
      strFilename  = strPath & strFilename  
      msgbox "The path and file to open is " & strFilename
   end if
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.