File Dialog Box Problem

K

Kedd123

Good Morning,

I am trying to find an easy way to place a file path into a text field on a
form. An image control will use this linked file path to display the image. I
have tried using the File Dialog Box in VB code, but I get the following
error:

"Compile Error User-Defined type not defined"

Any suggestions? I am using Access 2003. Below is the code I tried to use
(from "Help").

Dim dlgOpen As FileDialog

Set dlgOpen = Application.FileDialog( _
FileDialogType:=msoFileDialogOpen)

With dlgOpen
.AllowMultiSelect = True
.Show
End With
 
J

Jack Leach

As an alternative you can use the File Dialog API found at mvps...

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

I don't have any experience with the FileDialog object (which, if I
understand correctly, changes a bit from version to version), but have never
had any issues using the API to call the Common Dialog from windows.


hth


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
M

Mark Andrews

Here's the code I use:
---------------------------
Code for the button click event:
Private Sub cmdAssignDir_Click()
Dim strResult As String
strResult = BrowseFolder("Select Document Directory")
If (Nz(strResult, "") <> "") Then
Me.DocumentDirectory = strResult
End If
End Sub

Code in a module:


Option Compare Database
Option Explicit

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = vbNullString
End If
End Function
 
T

tbs

try this

Dim dlgOpen As FileDialog

Set dlgOpen = Application.FileDialog( _
FileDialogType:=msoFileDialogFilePicker)

With dlgOpen
.AllowMultiSelect = True
.Show
End With

note that msoFileDialogOpen and msoFileDialogSaveAs is not supported in in
access2003. If you really needed it to be msoFileDialogOpen, I would suggest
using the solutions provided on top. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top