Using =GetOpenFile() in a macro

G

Guest

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.
 
S

Steve Schapel

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.
 

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