scking is correct I always use something like the following instead of the common dialog control (place this code in a seperate module and it can be called from your command button):
*************BEGIN CODE***************************
Option Compare Database
Option Explicit
'declare library
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long 'create class type to call file open dialog box
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private mvarDialogTitle As String
Private mvarFileName As String
Private mvarFileTitle As String
Private mvarInitDir As String
Private mvarMaxFileSize As Integer
Private mvarhWnd As Long
Public Property Let hwnd(ByVal vData As Long)
' The owner of the window
mvarhWnd = vData
End Property
Public Property Get hwnd() As Long
hwnd = mvarhWnd
End Property
Public Function ShowOpen(Title As String) As String
Dim Extension As String, Name As String, StrPath As String
Dim OFN As OPENFILENAME
Dim Result
Dim retval As Long
Dim FileTitle As String
Dim intNullChr As Integer
On Error GoTo ErrHandler
Class_Initialize (Title) 'initialize class with title passed
With OFN
.hwndOwner = hwnd
.hInstance = 0
.lCustData = 0
.lpfnHook = 0
.lpstrFile = FileName & String$(MaxFileSize - Len(FileName) + 1, 0)
.lpstrFileTitle = FileTitle & Space$(256) 'set values for class object
.lpstrInitialDir = InitDir
.lpstrTitle = DialogTitle
.lStructSize = Len(OFN)
.nMaxFile = MaxFileSize
.nMaxFileTitle = 260
End With
retval = GetOpenFileName(OFN) 'open dialog box for user to select file
If retval > 0 Then
With OFN
StrPath = Left$(Trim$(.lpstrFile), .nFileOffset)
Name = Left$(Trim$(.lpstrFileTitle), Len(Trim$(.lpstrFileTitle)) - 1) 'get path,name and extension of file
Extension = Right$(Name, 3)
ShowOpen = StrPath & Name 'set to path and file name
End With
Else
ShowOpen = "Cancelled"
End If
Exit Function
ErrHandler:
Resume Next
End Function
Public Property Let MaxFileSize(ByVal vData As Integer)
' The maximum length of file name returned
mvarMaxFileSize = vData
End Property
Public Property Get MaxFileSize() As Integer
MaxFileSize = mvarMaxFileSize
End Property
Public Property Let InitDir(ByVal vData As String)
' Directory to open window in
mvarInitDir = vData
End Property
Public Property Get InitDir() As String
InitDir = mvarInitDir
End Property
Public Property Let FileTitle(ByVal vData As String)
' The name of the file without path
mvarFileTitle = vData
End Property
Public Property Get FileTitle() As String
FileTitle = mvarFileTitle
End Property
Public Property Let FileName(ByVal vData As String)
' Name of the file, including path
mvarFileName = vData
End Property
Public Property Get FileName() As String
FileName = mvarFileName
End Property
Public Property Let DialogTitle(ByVal vData As String)
' The name of the dialog box
mvarDialogTitle = vData
End Property
Public Property Get DialogTitle() As String
DialogTitle = mvarDialogTitle
End Property
Private Sub Class_Initialize(Title As String)
DialogTitle = Title
FileName = " "
FileTitle = " " 'set original values for class
InitDir = "C:\"
MaxFileSize = 260
hwnd = Screen.Application.hWndAccessApp
End Sub
****************end code*********************
Call the function ShowOpen with the title of the dialog box and it will return the path of the file selected. Regards,
gkprogrammer