Group:  Microsoft Access ยป microsoft.public.access.macros
Thread: Using =GetOpenFile() in a macro

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Using =GetOpenFile() in a macro
JornyO 10.07.2006 14:21:01
In a Macro I am creating, I want the user to be able to select a text file to
import, rather than having to specify an exact file name and path in the
macro. The macro uses the TransferText action, and I have tried using the
following function for the file name:

=GetOpenFile("text file")

but the dialogue box that opens will only look for .mdb files. Any idea how
I can get it to let me find a .txt file? I tried =GetOpenFile(".txt","text
file") but that still only looked for .mdb files. I know about the
=InputBox() function, but that isn't quite what I'm after.

One comment though...I realise that many people on here are programmers, but
the suggestion to "learn VBA" as my solution isn't always the most helpful
one. I'm a Civil Engineer who sometimes needs to work with databases. If
you asked a structural engineer for advice on how to patch a basement wall on
your house, and his answer to you was "Go learn to be an engineer", you
wouldn't consider that to be too helpful, would you? Just thought I'd pass
on the reminder that not everyone is a programmer, nor does everyone who
works with databases need to be a programmer. Having said that...I do
appreciate the specific help I get on this forum. Thank you in advance.
Re: Using =GetOpenFile() in a macro
Steve Schapel <schapel[ at ]mvps.org.ns> 11.07.2006 10:58:35
Jorny,

GetOpenFile() is not a function which is natively part of Access. This
function is only available to you by virtue of it being defined within a
standard module in your database as a user-defined function. This
presumably is because you have copied the FileSave API code from "The
Access Web". If you look through that code, you will see a line like
this...
strFilter = ahtAddFilterItem(strFilter, _
"Access (*.mdb)", "*.MDB;*.MDA")
You can add additional lines to the code, like this...
strFilter = ahtAddFilterItem(strFilter, _
"Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, _
"All Files (*.*)", "*.*")

I appreciate your comments about programming skills etc. I guess it
depends what you want to do. In this case, you are trying to achieve
something that is not directly catered for by the software, and so
requires you to go beyond the user-interface level of database
operation. If I wanted to earthquake-proof my basement wall and also
modify it so I can suspend a swimming pool across the basement, I guess
you would have to tell me that I am going beyond what is normally
undertaken by the home handyman.

--
Steve Schapel, Microsoft Access MVP


JornyO wrote:
[Quoted Text]
> In a Macro I am creating, I want the user to be able to select a text file to
> import, rather than having to specify an exact file name and path in the
> macro. The macro uses the TransferText action, and I have tried using the
> following function for the file name:
>
> =GetOpenFile("text file")
>
> but the dialogue box that opens will only look for .mdb files. Any idea how
> I can get it to let me find a .txt file? I tried =GetOpenFile(".txt","text
> file") but that still only looked for .mdb files. I know about the
> =InputBox() function, but that isn't quite what I'm after.
>
> One comment though...I realise that many people on here are programmers, but
> the suggestion to "learn VBA" as my solution isn't always the most helpful
> one. I'm a Civil Engineer who sometimes needs to work with databases. If
> you asked a structural engineer for advice on how to patch a basement wall on
> your house, and his answer to you was "Go learn to be an engineer", you
> wouldn't consider that to be too helpful, would you? Just thought I'd pass
> on the reminder that not everyone is a programmer, nor does everyone who
> works with databases need to be a programmer. Having said that...I do
> appreciate the specific help I get on this forum. Thank you in advance.

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net