open word doc

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to point my user out to a select from set of documents. Depending upon
which record is displayed on the form, the path and the first 6 characters of
the document are known. Can I show an open dialog box pointing to a specific
path and only looking at files prod111???.doc

thanks
 
judith,

I use the API method from http://www.mvps.org/access/api/api0001.htm
(use it if you ever intend on using the code on a different machine or
version of Access). You can create a filter like "prod111???.doc" or
modify the filter as the data in the form changes.

However, I've never been able to get this code to lock the user into a
single directory. Therefore, I would suggest that you *not* use the
file dialog, but instead use a listbox or combobox that you fill with
the available filenames.

Air Code
'In a standard module
Public Function ListMatchingFilesForRowSource(strPath as String,
strPattern as String)

'assumes strPath ends with a backslash

Dim strResult as String
Dim strNextFile as String

'Call Dir with parameters. First match will be returned.
' "" will be returned if there is no match

strNextFile = Dir(strPath & strPattern)

Do Until strNextFile = ""
'prepend semicolon (rowsource delimiter
strResult = ";" & strNextFile

'call to Dir with no param. gives next match
strNextFile = Dir()
Loop

'Trim the leading semicolon
ListMatchingFilesForRowSource = Mid(strResult, 2)

End Function

USAGE:

Sub Form_OnCurrent()

Me.lstFileList.Rowsource =
ListMatchingFilesForRowSource(Me.YourPathField, "prod" &
Me.YourNumberField & "???.doc")

End Sub
-----------
You will have to replace YourPathField and YourNumberField, etc, with
actually field names or constants. You'll also need to run the code
that I put in OnCurrent in the AfterUpdate event of each control that
would change the pattern/rowsource.

Hope this helps,

Kevin
 
Back
Top