Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Common Dialog Box

27 views
Skip to first unread message

Daedalus

unread,
Jan 6, 2010, 3:47:18 AM1/6/10
to
Hi

I can't find the proper way to use a common dialog box (file selection) on
one of my forms, though I'm sure it can not be too difficult. So I guess you
guys can help me out ?

Tanx in advance !

D


Keith Wilby

unread,
Jan 6, 2010, 9:44:22 AM1/6/10
to
"Daedalus" <fdpro...@hotmail.com> wrote in message
news:4b444ca1$0$398$5f6a...@news.scarlet.nl...

Search the help for "FileDialog".

Keith.
www.keithwilby.co.uk

(PeteCresswell)

unread,
Jan 6, 2010, 10:20:38 AM1/6/10
to
Per Daedalus:

>Hi
>
>I can't find the proper way to use a common dialog box (file selection) on
>one of my forms, though I'm sure it can not be too difficult. So I guess you
>guys can help me out ?

Greater minds than mine will probably chime in with simpler
solutions - like an invisible control that can be placed on the
form and addressed via VBA code.

Having said that, here's what I've been using for some years now.

Two modules:
- First is the common file dialog
- Second supports the error trapping calls in the first


Common File
-----------------------------------------------------------
Option Compare Database 'Use database order for string
comparisons
Option Explicit

Const mModuleName = "basCommonFileDialog"

Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
"GetOpenFileNameA" (mCFI As CommonFileInfo) As Integer
Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias
"GetSaveFileNameA" (mCFI As CommonFileInfo) As Integer
Public Declare Function CommDlgExtendedError Lib "comdlg32.dll"
Alias "CommDlgExtendedErrorA" () As Integer

Const gMainAccessWindowClassName = "OMain" '
Windows Class name for the main Access Window.

'---------------------------------------------
' Data structure used by the Common File dialog

Type CommonFileInfo
lStructSize As Long
hWndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
' lpstrCustomFilter As long
nMaxCustFilter As Long
nFilterIndex As Long
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 Long
End Type

Dim mCFI As CommonFileInfo

Global Const gOFN_READONLY = &H1
Global Const gOFN_FILEMUSTEXIST = &H1000
Global Const gOFN_OVERWRITEPROMPT = &H2
Global Const gOFN_HIDEREADONLY = &H4
Global Const gOFN_SHOWHELP = &H10 'Shows/hides "Help"
button on dialog
Global Const gOFN_CREATEPROMPT = &H2000
Global Const gOFN_EXPLORER = &H80000
'----------------------------------------------
' You also might want to use one or more of these...

'Global Const gOFN_NOCHANGEDIR = &H8
'Global Const gOFN_SHOWHELP = &H10
'Global Const gOFN_ENABLEHOOK = &H20
'Global Const gOFN_ENABLETEMPLATE = &H40
'Global Const gOFN_ENABLETEMPLATEHANDLE = &H80
'Global Const gOFN_NOVALIDATE = &H100
Global Const gOFN_ALLOWMULTISELECT = &H200
'Global Const gOFN_EXTENSIONDIFFERENT = &H400
'Global Const gOFN_PATHMUSTEXIST = &H800
'Global Const gOFN_CREATEPROMPT = &H2000
'Global Const gOFN_SHAREAWARE = &H4000
'Global Const gOFN_NOREADONLYRETURN = &H8000
'Global Const gOFN_NOTESTFILECREATE = &H10000

'Global Const gOFN_SHAREFALLTHROUGH = 2
'Global Const gOFN_SHARENOWARN = 1
'Global Const gOFN_SHAREWARN = 0


' ---------------------------------------------
' API Calls/Data structure/constants used by Browse Folders
dialog
'

Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA"
(ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As
BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal
pidList As Long, ByVal lpBuffer As String) As Long

Private Const mBIF_RETURNONLYFSDIRS = 1
Private Const mBIF_DONTGOBELOWDOMAIN = 2
Private Const mMAX_PATH = 260
Private Const mBIF_USENEWUI = &H40
Private Const mBIF_NOCREATEDIRS = &H200
Private Const mWM_USER = &H400
Private Const mBFFM_INITIALIZED = 1
Private Const mBFFM_SELCHANGED = 2
Private Const mBFFM_SETSTATUSTEXT = (mWM_USER + 100)
Private Const mBFFM_SETSELECTION = (mWM_USER + 102)


Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Dim mStartingDirectory As String


'---------------------------------------------

Function CommonFileDialog_Open(ByVal theDialogTitle As String,
ByVal theStartingDir As String, ByVal theSuffix As String, ByVal
theSuffixDescription As String) As String
1000 debugStackPush "CommonFileDialog_Open"
1001 On Error GoTo CommonFileDialog_Open_err

' PURPOSE: To issue a common file dialog and return whatever
the path the user chose
' ACCEPTS: - Title string for the dialog
' - Starting directory
' RETURNS: Chosen UNC or zero-length string if user didn't
choose anything

1002 Dim myDialogTitle As String
Dim myFileFilter As String
Dim myChosenFile As String
Dim myChosenPath As String
Dim myStartingDir As String
Dim myDefaultExtension As String
Dim myApiResult As Boolean

'---------------------------------------------------
' Define the filter string and allocate space in the "c"
string
'
1010 If Len(theSuffix) > 0 Then
1011 myFileFilter = theSuffixDescription & " (*." & theSuffix
& ")" & Chr$(0) & "*." & theSuffix & Chr$(0)
1019 End If

1021 myFileFilter = myFileFilter & "All Files (*.*) " & Chr$(0) &
"*.*" & Chr$(0)
1029 myFileFilter = myFileFilter & Chr$(0)

'---------------------------------------------------
' Allocate string space for the strings to be returned
'
1030 myChosenPath = Chr$(0) & Space$(255) & Chr$(0)
1039 myChosenFile = Space$(255) & Chr$(0)

1040 myDialogTitle = theDialogTitle & Chr$(0) 'Give
the dialog a caption title.
1049 myDefaultExtension = theSuffix & Chr$(0)

'1040 If theStartingDir & "" = "" Then
'1042 myStartingDir = CurDir$ 'This
is where the dialog points when opened
'1044 Else
1056 myStartingDir = theStartingDir
'1048 End If
1059 myStartingDir = myStartingDir & Chr$(0)

'-----------------------------------------------
' Load various other fields in the API's data structure
'
1100 With mCFI
1102 .hWndOwner = Application.hWndAccessApp
1103 .hInstance = 0
1104 .lpstrFilter = myFileFilter 'lstrcpy(myFileFilter,
myFileFilter)
1105 .nFilterIndex = 1
1106 .lpstrFile = myChosenPath 'lstrcpy(myChosenPath,
myChosenPath)
1107 .nMaxFile = Len(myChosenPath)
1108 .lpstrFileTitle = myChosenFile 'lstrcpy(myChosenFile,
myChosenFile)
1109 .nMaxFileTitle = Len(myChosenFile)
1110 .lpstrTitle = myDialogTitle 'lstrcpy(myDialogTitle,
myDialogTitle)
'1120 .flags = gOFN_READONLY
1121 .lpstrDefExt = myDefaultExtension
'lstrcpy(myDefaultExtension, myDefaultExtension)
1123 .lpstrCustomFilter = 0
1124 .nMaxCustFilter = 0
1125 .lpstrInitialDir = myStartingDir 'lstrcpy(myStartingDir,
myStartingDir)
1126 .nFileOffset = 0
1127 .nFileExtension = 0
1128 .lCustData = 0
1129 .lpfnHook = 0
1130 .lpTemplateName = 0
1131 .lStructSize = Len(mCFI) 'Allocate space for
the API's data structure
1199 End With

'----------------------------------------------
' Pass the data structure to the Windows API, which
' will display the Open Dialog form.

' myChosenPath will have an embedded Chr$(0) at the end
' We strip this character from the string.

1910 myApiResult = GetOpenFileName(mCFI)
1911 If myApiResult = True Then
1912 myChosenPath = mCFI.lpstrFile
1920 myChosenPath = Left$(myChosenPath, InStr(myChosenPath,
Chr$(0)) - 1)
1930 CommonFileDialog_Open = myChosenPath
1940 Else
1950 CommonFileDialog_Open = ""
1999 End If

CommonFileDialog_Open_xit:
debugStackPop
On Error Resume Next
Exit Function

CommonFileDialog_Open_err:
bugAlert True, ""
Resume CommonFileDialog_Open_xit
End Function
Public Function CommonFileDialog_Save(ByVal theDialogTitle As
String, theStartingDir, ByVal theSuggestedName As String, ByVal
theSuffix As String, ByVal theSuffixDescription As String) As
String
debugStackPush "CommonFileDialog_Save"
On Error GoTo CommonFileDialog_Save_err

' PURPOSE: To present Windows' Common File Dialog in "Save" mode.
' ACCEPTS: - A title for the window
' - A path to the directory where the window should
initially be pointing to
' - A default name for the file
'
' NOTES: 1) If the user types something shorter than the
suggested name, .lpstrFile
' contains the entire suggested name overlayed with
the shorter name.
' The shorter name, however, is terminated with a hex
zero, so we just
' have to scan for that terminator to extract the
correct file path.

Dim myDialogTitle As String
Dim myFileFilters As String
Dim mySpecifiedFile As String
Dim mySpecifiedPath As String
Dim myStartingDir As String
Dim myDefaultExtension As String
Dim myApiResult As Boolean
Dim L As Long
Dim myPath As String

'---------------------------------------------------
' Define the filter string and allocate space in the "c" string
'
myFileFilters = theSuffixDescription & "(*." & theSuffix & ")" &
Chr$(0) & "*." & theSuffix & Chr$(0)
myFileFilters = myFileFilters & "All Files" & Chr$(0) & "*.*" &
Chr$(0)
myFileFilters = myFileFilters & Chr$(0)
'---------------------------------------------------
' Allocate string space for the returned strings.
'
If theSuggestedName & "" <> "" Then
mySpecifiedPath = theSuggestedName & Chr$(0) & Space$(255 -
Len(theSuggestedName)) & Chr$(0)
Else
mySpecifiedPath = Chr$(0) & Space$(255) & Chr$(0)
End If

mySpecifiedFile = Space$(255) & Chr$(0)

myDialogTitle = theDialogTitle & Chr$(0) 'Give the
dialog a caption title.
myDefaultExtension = "TXT" & Chr$(0) 'If user
does not specify an extension, append TXT.

If theStartingDir & "" = "" Then
myStartingDir = CurDir$ 'This is
where the dialog points when opened
Else
myStartingDir = theStartingDir
End If

myStartingDir = myStartingDir & Chr$(0)

'-----------------------------------------------
' Load various other fields in the API's data structure
'
With mCFI
.hWndOwner = Application.hWndAccessApp
.hInstance = 0
.lpstrFilter = myFileFilters 'lstrcpy(myFileFilters,
myFileFilters)
.nFilterIndex = 1
.lpstrFile = mySpecifiedPath
.nMaxFile = Len(mySpecifiedPath)
.lpstrFileTitle = mySpecifiedFile
.nMaxFileTitle = Len(mySpecifiedFile)
.lpstrTitle = myDialogTitle
.Flags = gOFN_OVERWRITEPROMPT Or gOFN_HIDEREADONLY
.lpstrDefExt = myDefaultExtension
.lpstrCustomFilter = 0
.nMaxCustFilter = 0
.lpstrInitialDir = myStartingDir
.nFileOffset = 0
.nFileExtension = 0
.lCustData = 0
.lpfnHook = 0
.lpTemplateName = 0
.lStructSize = Len(mCFI) 'Allocate space for the API's
data structure
End With

'----------------------------------------------
' Pass the data structure to the Windows API, which
' will display the Open Dialog form.

' mySpecifiedPath will have an embedded Chr$(0) at the
' end. You may wish to strip this character from the string.

myApiResult = GetSaveFileName(mCFI)
If myApiResult = True Then
' mySpecifiedPath = Left$(mySpecifiedPath,
InStr(mySpecifiedPath, Chr$(0)) - 1)
L = InStr(1, mCFI.lpstrFile, Chr$(0))
If L > 0 Then 'Take everything up to the first hex
zero
myPath = Left$(mCFI.lpstrFile, L - 1)
Else
myPath = ""
End If

Else
myPath = ""
End If

CommonFileDialog_Save = myPath

CommonFileDialog_Save_xit:
debugStackPop
On Error Resume Next
Exit Function

CommonFileDialog_Save_err:
bugAlert True, ""
Resume CommonFileDialog_Save_xit
End Function
Public Function BrowseForFolder(ByVal theDialogTitle As String,
theStartingDirectory As String) As String
2000 debugStackPush "BrowseForFolder"
2001 On Error GoTo BrowseForFolder_err

' PURPOSE: To issue a Browse Folders dialog and return
whatever the directory the user chose
' ACCEPTS: - Title string for the dialog
' RETURNS: Chosen directory path or zero-length string if user
didn't choose anything

2002 Dim myBI As BrowseInfo

Dim myTitle As String
Dim myBuffer As String
Dim myResult As Long

Dim myIdListPtr As Long

2010 myTitle = theDialogTitle
2019 mStartingDirectory = theStartingDirectory

2020 With myBI
2021 .hWndOwner = Application.hWndAccessApp ' Owner Form
2022 .lpszTitle = lstrcat(myTitle, "")
2023 .lpfnCallback = GetAddressOfFunction(AddressOf
browseCallback)
2024 .ulFlags = mBIF_RETURNONLYFSDIRS + mBIF_DONTGOBELOWDOMAIN
+ mBIF_USENEWUI + mBIF_NOCREATEDIRS
2029 End With

2030 myResult = SHBrowseForFolder(myBI)

2040 If (myResult) Then
2041 myBuffer = Space(mMAX_PATH)
2042 SHGetPathFromIDList myResult, myBuffer
2043 myBuffer = Left(myBuffer, InStr(myBuffer, vbNullChar) - 1)
2044 BrowseForFolder = myBuffer
2049 End If

BrowseForFolder_xit:
debugStackPop
On Error Resume Next
Exit Function

BrowseForFolder_err:
bugAlert True, ""
Resume BrowseForFolder_xit
End Function
Private Function GetAddressOfFunction(theFunctionPointer As Long)
As Long
debugStackPush mModuleName & ": GetAddressofFunction"
On Error GoTo GetAddressofFunction_err

' PURPOSE: To assign a function pointer to a variable
' ACCEPTS: Function pointer
' RETURNS: Variable

GetAddressOfFunction = theFunctionPointer

GetAddressofFunction_xit:
debugStackPop
On Error Resume Next
Exit Function

GetAddressofFunction_err:
bugAlert True, ""
Resume GetAddressofFunction_xit
End Function
Private Function browseCallback(ByVal theWindowPointer As Long,
ByVal theDialogMessage As Long, ByVal lp As Long, ByVal pData As
Long) As Long
' NO ERROR TRAPPING - to prevent an error from propagating back
into the calling process - suggested by MS' Q179378
On Error Resume Next

' PURPOSE: To provide a vehicle for initializing the path in
SHBrowseForFolder.
' ACCEPTS: - Pointer to window that owns the dialog
' - 'Message' from dialog telling us what it's current
state is
' - (apparently-unused 'lp')
' - (apparently-unused 'pData')
' USES: Module-level variable that contains path of directory
we want to initialize dialog to
' RETURNS: Zero, no matter what

Dim L As Long
Dim myBuffer As String

Select Case theDialogMessage
Case mBFFM_INITIALIZED
Call SendMessage(theWindowPointer, mBFFM_SETSELECTION, 1,
mStartingDirectory)

Case mBFFM_SELCHANGED
myBuffer = Space(mMAX_PATH)

L = SHGetPathFromIDList(lp, myBuffer)
If L = 1 Then
Call SendMessage(theWindowPointer, mBFFM_SETSTATUSTEXT,
0, myBuffer)
End If
End Select

browseCallback = 0
End Function

-----------------------------------------------------------


Error Trapping
-----------------------------------------------------------
Option Compare Database 'Use database order for string
comparisons
Option Explicit

' This module contains the routines used to trap/log errors and
' show the "bugAlert" screen. It is derived from my "real"
bugAlert module,
' but stripped down to the bare essentials to the end of
placating any code that
' calls the bugAlert routines (namely debugStackPush(),
debugStackPop, and bugAlert().

' Every procedure should have the following boilerplate in it to
implement
' error trapping. What I do is create a .txt file with that
boilerplate
' in it, with the single quotes removed. Then I just copy/paste
from the
' .txt file each time I starting writing a routine. After
pasting in the
' boilerplate, I just do a rename of "xxx" to the procedure name.

' Pete Cresswell
' 3/3/2003


' -----------------------------------------
' debugStackPush Me.Name & ": xxx"
' On Error GoTo xxx_err

'' PURPOSE: To

'xxx_xit:
' debugStackPop
' On Error Resume Next
' Exit Sub
'
'xxx_err:
' bugAlert True, ""
' Resume xxx_xit
' -----------------------------------------

Const mModuleName = "basBugAlert_Lite"


Const mDebugStackTotalSize = 52
Global gDebugStack(mDebugStackTotalSize)
Global Const gStackLimit = 50

Global gStackPointer As Integer

Sub bugAlert(ByVal theDisplaySwitch As Integer, ByVal
theSupplementalMessage As String)

' PURPOSE: To show information about the trapped error
' ACCEPTS: - A switch that the "real" version of bugAlert uses to
decide how large and detailed
' a screen to show
' - Optional message text that the calling routine might
want to supply for
' display with the error message
'
' NOTES: 1) The "real" version logs the error in a text file.

Dim myErrorLine As Long
Dim myErrorNumber As Long
Dim myErrorMessage As String
Dim myErrorLocation As String

myErrorLine = Erl 'Capture relevant info ASAP.
Dunno why, but intuitively it seems like a good idea.
myErrorNumber = Err
myErrorMessage = Error$
myErrorLocation = gDebugStack(gStackPointer)

MsgBox myErrorLocation & ", Line " & Format$(myErrorLine,
"000000") & " " & Format$(myErrorNumber, "0000") & ": " &
myErrorMessage & vbCrLf & theSupplementalMessage, vbCritical,
"There's Trouble In River City!"

End Sub
Sub debugStackPop()
On Error GoTo debugStackPop_err

' PURPOSE: To pop the last procedure name off the top of the
debug stack

Dim i As Integer

If gStackPointer <= gStackLimit Then
gDebugStack(gStackPointer) = ""
End If

gStackPointer = gStackPointer - 1

If gStackPointer < 0 Then
gStackPointer = 0
End If

debugStackPop_xit:
On Error Resume Next
Exit Sub

debugStackPop_err:
MsgBox "debugStackPop() failed. Error " & Str(Err) & ": " &
Error$, 48, "Error In Error Handler"
Resume debugStackPop_xit
End Sub
Sub debugStackPush(ByVal theProcedureName As String)
On Error GoTo debugStackPush_err

' PURPOSE: To push a procedure name into the debug stack
' ACCEPTS: The procedure name

Dim i As Integer

gStackPointer = gStackPointer + 1

If gStackPointer <= gStackLimit Then
gDebugStack(gStackPointer) = theProcedureName
Else
gDebugStack(gStackLimit + 2) = theProcedureName
End If

debugStackPush_xit:
On Error Resume Next
Exit Sub

debugStackPush_err:
MsgBox "debugStackPush() failed. Error " & Str(Err) & ": " &
Error$, 48, "Error In Error Handler"
Resume debugStackPush_err
End Sub
Sub zzTestBugAlert()
debugStackPush mModuleName & ": zzTestBugAlert"
On Error GoTo zzTestBugAlert_err

' PURPOSE: To supply a model for using the BugAlert routines and
to demo the routines
'
' NOTES: 1) Fire up a Debug window and type "zzTestBugAlert"

DoCmd.OpenForm "frmNon-Existant"

zzTestBugAlert_xit:
debugStackPop
On Error Resume Next
Exit Sub

zzTestBugAlert_err:
bugAlert False, "This is the supplemental text...."
Resume zzTestBugAlert_xit
End Sub
-----------------------------------------------------------
--
PeteCresswell

Daedalus

unread,
Jan 6, 2010, 10:58:26 AM1/6/10
to

"Keith Wilby" <he...@there.com> schreef in bericht
news:4b44a...@glkas0286.greenlnk.net...

I can find that help-info, but as soon as I refer to 'FileDialog' I get an
error. I suppose I should include a certain type of control, but don't know
which :-( And 'Microsoft Common Dialog' is not in the list ::-(


Keith Wilby

unread,
Jan 6, 2010, 11:11:46 AM1/6/10
to
"Daedalus" <fdpro...@hotmail.com> wrote in message
news:4b44b1ac$0$402$5f6a...@news.scarlet.nl...

>
>
> I can find that help-info, but as soon as I refer to 'FileDialog' I get an
> error. I suppose I should include a certain type of control, but don't
> know which :-( And 'Microsoft Common Dialog' is not in the list ::-(
>

What version of Access are you using? The method I suggested is available
from 2k3 onwards IIRC.

Daedalus

unread,
Jan 6, 2010, 11:23:01 AM1/6/10
to

"Keith Wilby" <he...@there.com> schreef in bericht
news:4b44b60c$1...@glkas0286.greenlnk.net...


I'm using Office (Access) 2003. I suppose I need to include a add-in or so ?
The error I get is on line
Dim dlgOpen As FileDialog
and it says (translated from Dutch)
Compilation error
A userdefined datatype is not defined


Keith Wilby

unread,
Jan 6, 2010, 11:35:33 AM1/6/10
to
"Daedalus" <fdpro...@hotmail.com> wrote in message
news:4b44b77a$0$395$5f6a...@news.scarlet.nl...

>
>
>
> I'm using Office (Access) 2003. I suppose I need to include a add-in or so
> ?
> The error I get is on line
> Dim dlgOpen As FileDialog
> and it says (translated from Dutch)
> Compilation error
> A userdefined datatype is not defined
>

This works for me. strTitle contains something like "Select a file." and
strType contains the file extension of the file to be chosen (I believe that
is optional):

Sub GetFile(strTitle As String, strType As String)

Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant

With fd
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add strType & " files", "*." & strType
.Title = strTitle
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
strFilePath = vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
If MsgBox("You did not select a file. Do you want to cancel the
operation?", _
vbYesNo + vbQuestion, "No File Selected") = vbYes Then
Set fd = Nothing
DoCmd.Hourglass False
Me.lblHeader.Caption = "My Title"
strFilePath = "UserAbort"
Exit Sub
Else
'Do something to handle the user cancelling if necessary
End If
End If
End With

End Sub

Daedalus

unread,
Jan 6, 2010, 11:51:35 AM1/6/10
to

"Keith Wilby" <he...@there.com> schreef in bericht
news:4b44bba0$1...@glkas0286.greenlnk.net...


Keith

I tried this, but get exactly the same error as soon as entering the sub
'GetFile'
Any idea where that 'FileDialog' is coming from ?
Tanx !

D


Keith Wilby

unread,
Jan 6, 2010, 12:13:55 PM1/6/10
to
"Daedalus" <fdpro...@hotmail.com> wrote in message
news:4b44be21$0$394$5f6a...@news.scarlet.nl...

>
>
> I tried this, but get exactly the same error as soon as entering the sub
> 'GetFile'
> Any idea where that 'FileDialog' is coming from ?
> Tanx !
>
>

It might be a missing library reference but I'm not sure which. Try adding
Office 11 Object Library and/or ActiveX Data Objects. I assume you're
calling the sub from the immediate window and supplying the arguments.

Keith.

Daedalus

unread,
Jan 6, 2010, 12:48:14 PM1/6/10
to

"Keith Wilby" <he...@there.com> schreef in bericht
news:4b44c49d$1...@glkas0286.greenlnk.net...

Keith

You're the BEST !

I had already the Access 11.0 Object Library included, but it's the Office
11.0 Object Library I needed.

Tanx man !

D


David W. Fenton

unread,
Jan 6, 2010, 8:54:09 PM1/6/10
to
"Keith Wilby" <he...@there.com> wrote in
news:4b44a...@glkas0286.greenlnk.net:

> Search the help for "FileDialog".

That will be available only if you have a reference to the Office
Automation library. You don't have to have the reference to use the
FileDialog object (though you need it if you want to use the
FileDialog object's data types).

I would recommend not using the FileDialog object, but instead using
the Windows API call, which Pete Cresswell provided code for and
which can also be found here:

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

The Windows API file open will work as long as the Win32 API is
supported, whereas MS could decide to remove the FileDialog object
from Access/Office at any time (as it did with the FileSearch object
in Office 2007).

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

David W. Fenton

unread,
Jan 6, 2010, 8:54:54 PM1/6/10
to
"Keith Wilby" <he...@there.com> wrote in
news:4b44bba0$1...@glkas0286.greenlnk.net:

> Dim fd As FileDialog

This will not work unless you have a reference to the Office
Automation library.

--

David W. Fenton

unread,
Jan 6, 2010, 8:55:47 PM1/6/10
to
"Daedalus" <fdpro...@hotmail.com> wrote in
news:4b44cb69$0$403$5f6a...@news.scarlet.nl:

> I had already the Access 11.0 Object Library included, but it's
> the Office 11.0 Object Library I needed.

You've been getting advice from someone who doesn't really
understand the approach he's recommending. Otherwise, he would have
understood that for the code he was providing to work, you'd have
needed the reference.

Keith Wilby

unread,
Jan 7, 2010, 4:25:42 AM1/7/10
to
"David W. Fenton" <XXXu...@dfenton.com.invalid> wrote in message
news:Xns9CF8D4EA9974Cf9...@74.209.136.95...

> "Daedalus" <fdpro...@hotmail.com> wrote in
> news:4b44cb69$0$403$5f6a...@news.scarlet.nl:
>
>> I had already the Access 11.0 Object Library included, but it's
>> the Office 11.0 Object Library I needed.
>
> You've been getting advice from someone who doesn't really
> understand the approach he's recommending. Otherwise, he would have
> understood that for the code he was providing to work, you'd have
> needed the reference.
>
>

Still got that chip on your shoulder Mr Fenton? And why am I not in your KF
any more? For the record, the OP was "getting" advice from someone who no
longer works with Access and VBA on a regular basis and is rather rusty with
it. However, if I can help someone I still will try. It seems that I did
and you just choose to be arsey about it. Speaks volumes about you sir
which is nothing to be proud of. It just goes to show that even some of the
most expert of people can be complete twats at the same time, which is a
shame.

Please KF me again and keep your pathetic drivel to yourself. Although I
rather doubt that the latter is going to happen.

Keith Wilby

unread,
Jan 7, 2010, 4:29:08 AM1/7/10
to
"David W. Fenton" <XXXu...@dfenton.com.invalid> wrote in message
news:Xns9CF8D4A3F9CEDf9...@74.209.136.95...

>
> I would recommend not using the FileDialog object, but instead using
> the Windows API call, which Pete Cresswell provided code for and
> which can also be found here:
>
> http://mvps.org/access/api/api0001.htm
>

Of course, why use a few lines of code when you can use reams and reams of
the stuff?

> The Windows API file open will work as long as the Win32 API is
> supported, whereas MS could decide to remove the FileDialog object
> from Access/Office at any time (as it did with the FileSearch object
> in Office 2007).
>
>

They could choose to remove Access completely too. Should we migrate
everything to Oracle? Picky, picky, picky.

Keith Wilby

unread,
Jan 7, 2010, 4:36:42 AM1/7/10
to
"Daedalus" <fdpro...@hotmail.com> wrote in message
news:4b44cb69$0$403$5f6a...@news.scarlet.nl...

>
>
> Keith
>
>
>
> You're the BEST !
>

Hardly, but thanks.

> I had already the Access 11.0 Object Library included, but it's the Office
> 11.0 Object Library I needed.
>
> Tanx man !
>
>

Glad to nudge you roughly in the right direction, even though I couldn't
quote chapter and verse on library references from memory like some anally
retentive geek :)

Keith.

Bilky White

unread,
Jan 8, 2010, 3:36:14 PM1/8/10
to
On 07/01/2010 01:55, David W. Fenton wrote:
>
> You've been getting advice from someone who doesn't really
> understand the approach he's recommending. Otherwise, he would have
> understood that for the code he was providing to work, you'd have
> needed the reference.
>

How the F do *you* know what a complete stranger does and does not
understand? Arrogant, elitist moron.

David W. Fenton

unread,
Jan 8, 2010, 6:39:53 PM1/8/10
to
Bilky White <a...@b.com> wrote in
news:oMadncuo54CuCtrW...@bt.com:

It's quite clear he doesn't understand the issues from the content
of his answers. Or do you think the answers were adequate?

Bilky White

unread,
Jan 9, 2010, 6:21:40 AM1/9/10
to
On 08/01/2010 23:39, David W. Fenton wrote:
> Bilky White<a...@b.com> wrote in
> news:oMadncuo54CuCtrW...@bt.com:
>
>> How the F do *you* know what a complete stranger does and does not
>> understand? Arrogant, elitist moron.
>
> It's quite clear he doesn't understand the issues from the content
> of his answers.


Why? You might perceive someone's understanding of something from a few
words but that is merely your perception and opinion, not fact. He's
already admitted to being "rusty" so perhaps he understood it perfectly
at one stage but just couldn't bring it to mind and didn't have time to
re-research it. Wow, a flawed human being - whatever next? It would
appear that you didn't consider that possibility, you just saw an
opportunity to pounce and grabbed it with both hands.

>
> Or do you think the answers were adequate?
>

Did the answers get the OP up and running? Did the OP go away happy?
Yes is the answer to both and that is fact. Is that not the purpose of
these groups? Yes is the answer and that is fact. So, on that basis I
would say that the answers were adequate. Not full of blinding geeky
and possibly dull detail perhaps, but adequate. If the OP wants to know
*why* they need that reference then surely they will ask. As yet, they
haven't.

How sad of you that you felt it necessary to criticize someone in public
for trying to help someone else. Are you just angry that you didn't get
in there first to post an elitist answer with detail down to the enth
degree, to give you a nice warm feeling of condescending superiority?
Sounds like it to me.

Bilky White

unread,
Jan 9, 2010, 6:26:11 AM1/9/10
to
On 07/01/2010 09:25, Keith Wilby wrote:
>
> Please KF me again and keep your pathetic drivel to yourself.
>

LOL I've never heard of anyone *asking* to be kill-filed before!

Bilky White

unread,
Jan 9, 2010, 6:50:23 AM1/9/10
to
On 07/01/2010 01:54, David W. Fenton wrote:
> "Keith Wilby"<he...@there.com> wrote in
> news:4b44bba0$1...@glkas0286.greenlnk.net:
>
>> Dim fd As FileDialog
>
> This will not work unless you have a reference to the Office
> Automation library.
>

Does the fact that it's actually a reference to the Office 11 Object
Library that's required mean that you don't understand this issue? By
your logic else-thread that would be a yes.

David W. Fenton

unread,
Jan 9, 2010, 3:47:43 PM1/9/10
to
Bilky White <a...@b.com> wrote in
news:RNSdnVAKs74l-9XW...@bt.com:

> Did the answers get the OP up and running?

Many wrong answers *seem* to work. Some people advise On Error
Resume Next as a solution to avoiding an error, but it's still a
very bad solution.

David W. Fenton

unread,
Jan 9, 2010, 3:51:23 PM1/9/10
to
Bilky White <a...@b.com> wrote in
news:R42dnQSEEJbs8NXW...@bt.com:

Eh? You need a reference to the version-specific Office library.

In Access previous to 2003 (or maybe 2002 -- I don't have it and
never used it long enough to find out about things I don't use), you
*had* to have the Office Automation reference in order to use the
FileDialog object at all. In A2003 (or A2002), they adding a
FileDialog object to the the top-level Access application object,
This gets you to the object, but doesn't get you any of the
enumerations or data types used by the FileDialog object.

So, my answer was, in fact, correct. There was no need to specify
*which* version of the Office Object library.

And, goodbye to you...

<PLONK>

David W. Fenton

unread,
Jan 9, 2010, 3:55:37 PM1/9/10
to
"Keith Wilby" <he...@there.com> wrote in
news:4b45a860$1...@glkas0286.greenlnk.net:

> Please KF me again

Don't worry -- you're still in my killfile, and will remain there.

But your "advice" was quoted by others, so I saw it anyway. If I
reply to an answer of yours, it's because I've seen something of
yours quoted by someone else that is so egregiously wrong that I've
followed the Reference tree up to your post in order to refute you.

Don't like it?

Then stop posting stupid things.

Bilky White

unread,
Jan 9, 2010, 4:00:09 PM1/9/10
to
On 09/01/2010 20:47, David W. Fenton wrote:
> Bilky White<a...@b.com> wrote in
> news:RNSdnVAKs74l-9XW...@bt.com:
>
>> Did the answers get the OP up and running?
>
> Many wrong answers *seem* to work.
>
>
>

But the answer wasn't wrong! It was right but was just missing a bit of
info to make it complete.

Bilky White

unread,
Jan 9, 2010, 4:01:03 PM1/9/10
to
On 09/01/2010 20:51, David W. Fenton wrote:
> Bilky White<a...@b.com> wrote in
> news:R42dnQSEEJbs8NXW...@bt.com:
>
>
> And, goodbye to you...
>
> <PLONK>
>

My work here is done.

Bilky_White

unread,
Jan 10, 2010, 5:52:01 AM1/10/10
to
On 09/01/2010 20:55, David W. Fenton wrote:
> "Keith Wilby"<he...@there.com> wrote in
> news:4b45a860$1...@glkas0286.greenlnk.net:
>
>> Please KF me again
>
> Don't worry -- you're still in my killfile, and will remain there.
>
> But your "advice" was quoted by others, so I saw it anyway.

It wasn't "advice" you moronic arse, it was an answer to a question. A
valid answer.

>
> Then stop posting stupid things.
>

Can you provide some evidence to support "stupidity"? Thought not. Try
leading by example. If you don't like to lose an argument then don't
start one.

Keith Wilby

unread,
Jan 11, 2010, 4:22:00 AM1/11/10
to
"David W. Fenton" <XXXu...@dfenton.com.invalid> wrote in message
news:Xns9CFBA20891783f9...@74.209.136.100...

> "Keith Wilby" <he...@there.com> wrote in
> news:4b45a860$1...@glkas0286.greenlnk.net:
>
>> Please KF me again
>
> Don't worry -- you're still in my killfile, and will remain there.
>

So how did you manage to reply directly to my post?

> But your "advice" was quoted by others, so I saw it anyway. If I
> reply to an answer of yours, it's because I've seen something of
> yours quoted by someone else that is so egregiously wrong that I've
> followed the Reference tree up to your post in order to refute you.
>

As already noted else-thread, I answered a question. It's *that* simple,
even you should be able to grasp that. I didn't offer any advice, I offered
a solution.

> Don't like it?
>

Don't care mate.

> Then stop posting stupid things.
>
>

I think we're all well aware where the stupidity in this thread originates.

Keith Wilby

unread,
Jan 11, 2010, 4:22:46 AM1/11/10
to
"Bilky White" <a...@b.com> wrote in message
news:GMmdnQWyCb8cc9XW...@bt.com...

Fenton always runs away and hides when he loses an argument :)

Keith Wilby

unread,
Jan 11, 2010, 4:24:38 AM1/11/10
to
"David W. Fenton" <XXXu...@dfenton.com.invalid> wrote in message
news:Xns9CFBA0B16B1FAf9...@74.209.136.100...

> Bilky White <a...@b.com> wrote in
> news:RNSdnVAKs74l-9XW...@bt.com:
>
>> Did the answers get the OP up and running?
>
> Many wrong answers *seem* to work. Some people advise On Error
> Resume Next as a solution to avoiding an error, but it's still a
> very bad solution.
>
>

Irrelevant clap-trap posted by someone desperately trying to justify the
unjustifiable. Can you quote which part of the solution I offered was
wrong?

Keith Wilby

unread,
Jan 11, 2010, 4:27:32 AM1/11/10
to
"Bilky White" <a...@b.com> wrote in message
news:RNSdnVMKs75b-tXW...@bt.com...

> On 07/01/2010 09:25, Keith Wilby wrote:
>>
>> Please KF me again and keep your pathetic drivel to yourself.
>>
>
> LOL I've never heard of anyone *asking* to be kill-filed before!
>

I'm tired of Mr Fenton and his silly microscope, pouncing on the tiniest of
discrepancies in others' posts. Brilliant at Access but woefully inadequate
with manners.

Keith Wilby

unread,
Jan 11, 2010, 4:31:33 AM1/11/10
to
"David W. Fenton" <XXXu...@dfenton.com.invalid> wrote in message
news:Xns9CFBA150EFEB9f9...@74.209.136.100...

> Bilky White <a...@b.com> wrote in
> news:R42dnQSEEJbs8NXW...@bt.com:
>
>> On 07/01/2010 01:54, David W. Fenton wrote:
>>> "Keith Wilby"<he...@there.com> wrote in
>>> news:4b44bba0$1...@glkas0286.greenlnk.net:
>>>
>>>> Dim fd As FileDialog
>>>
>>> This will not work unless you have a reference to the Office
>>> Automation library.
>>
>> Does the fact that it's actually a reference to the Office 11
>> Object Library that's required mean that you don't understand this
>> issue? By your logic else-thread that would be a yes.
>
> Eh? You need a reference to the version-specific Office library.
>
>

So you're saying that "Office Automation library" = "Office Object Library"?
Care to come out of your big sulk to explain that?

0 new messages