Common Dialog Control in Access 2003?

T

Tom Lake

I want to be able to add a File Open control to an Access 2003 form
which, IIRC, I could do in Access 97. When I try to add the Microsoft
Common Dialog Control 6.0 to a form I get an error that says I'm not
licensed to use it. I'd rather not use an API call if possible. Is there
a Common Dialog Control I can use with 2003?

TIA

Tom Lake
 
A

Allen Browne

There has always been licensing and versioning problems and other bugs in
the common dialog control.

There is a FileDialog object in the Office library, but it is also
problematic. Doesn't work with runtime/mde. Requires an extra reference
(with the chance of breaking apps.) And it doesn't work at all for the Save
As, even though it appears to offer that option.

The API call is still the only thing that works reliably. It may look a
little daunting if you have not used APIs before, but it's straight forward
enough. Just copy the code into a standard module from:
http://www.mvps.org/access/api/api0001.htm

You can then get a file name into a string with 3 lines of code:

Function GetFile() As String
Dim msaof As MSA_OPENFILENAME
Call MSA_GetOpenFileName(msaof)
GetFile = Trim(msaof.strFullPathReturned)
End Function
 
D

Douglas J. Steele

Hate to argue, Allen, but your example doesn't seem to be related to the
code from http://www.mvps.org/access/api/api0001.htm: there is no
MSA_OPENFILENAME type defined in that code, nor a sub named
MSA_GetOpenFileName.

I agree that the API approach is definitely the way to go, but if you copy
Ken's code from that website, you need the following to get a filename back:

Dim strFilter As String
Dim strInputFileName as string

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
In fact, you don't have to define strFilter if you don't want to limit the
output to specific file extensions. You could simply use:

Dim strInputFileName as string

strInputFileName = ahtCommonFileOpenSave( _
OpenFile:=True, _
DialogTitle:="Please select an input file...")
 
A

Allen Browne

Thanks Doug.

I guess I didn't use Ken's code as the API source. Thanks for picking that
up.
 

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