Store value from Common Dialog Box

  • Thread starter Thread starter Matt Weyland
  • Start date Start date
M

Matt Weyland

does anyone have some information or code on how to create
an instance of a common dialog box that will open a window
similar to open file window. After this is opened and a
user locates the file they want to reference, have the
dialog box store the values of the file in one variable
and the path in another?

The use for this is to allow users to create document
links via the DB, which will be stored in a table with
DocName, DocPath, PK(DocID), and DocType (which will be
determined by the extension).

any assistance with this is greatly appreciated.
 
See:

http://www.mvps.org/access/api/api0001.htm

Note that the article also states that you can use the Office Common Dialog
object (Access 2000 and later). You must first load a reference to the
Office library and then call it something like this:

Dim strFilePath As String, strPath As String
Dim fdgO As Office.FileDialog

Set fdgO = Application.FileDialog(msoFileDialogFilePicker)
With fdgO
' Select only one folder
.AllowMultiSelect = False
' Set the dialog title
.Title = "Locate Folder Containing Sample Data"
' Set the button caption
.ButtonName = "Choose"
' Make sure the filter list is clear
.Filters.Clear
' Add one filter
.Filters.Add "All Files", "*.*", 1
' Set the filter index to 1
.FilterIndex = 1
' Set the initial file name
.InitialFileName = "C:\My Documents"
' Show file details
.InitialView = msoFileDialogViewDetails
' Show the dialog and test the return
If .Show = 0 Then
MsgBox "You failed to select the correct file.", vbCritical
' Done
Exit Function
End If
' Should be only one path name - grab it
strFilePath = .SelectedItems(1)
End With
' Get just the path
strPath = Left(strFilePath, InStrRev(strFilePath, "\") - 1)


--
John Viescas, author
"Microsoft Office Access 2003 Inside Out" (coming soon)
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 
Thanks for the information. I think this would work, but
I keep getting the following error:

You dont have the license necessary to run this ActiveX
Control

This is a little bewildering. I am currently running a
fully licsened regiestered version of Office 2000. Any
ideas as to how I can get around this? I can use MSAccess
applications with common dialog controls included, but I
cant create a new instance.

THX

MW
 
Back
Top