Trying Ken's API file dialog for first time

  • Thread starter Thread starter Kou Vang
  • Start date Start date
K

Kou Vang

I have been too dependant on the filedialog ocx's and am finally saying to
hell with them and moving to API. I've never used the API before, I can
understand what it's doing, but my question is, do I just save it to a module
and call it from another module? I have done shell calls, but never API.
Thanks.

Kou
 
You can save it in a standard module (not a form, not a class, not a report)
and if the function is public, you can call it from any place accepting a
call to a VBA function.

You can also keep the module(s) in another database (mdb file) and add that
other database in the references of your actual database: from VBE, the
menu Tools | References ... button Browse, then select the type mdb in the
combo box near the bottom, and navigate to the database to be added as
reference. Doing it this way, you don't have to spread the same code at many
places (by copying it), but you cannot make 'individual' modifications to
suit particular need, since the code, in the reference, could be use by many
of your applications (eventually).


Vanderghast, Access MVP
 
I tried to just paste the first part, up to the global constants, and tried
the saveas example code at the very beginning. I have the module in Excel
that I have assigned to a button on the toolbar. Now when I press the
button, it says it can't find the Macro I assigned to it? What happened?

Kou
 
You have to copy the whole module, including the constants, and (preferably)
paste it into a new module of your application and be sure you don't name
the module with the same name as one of the function it exposes. Sometimes
you may also need to copy other modules/classes which are involved in the
module that interest you, but, about your actual problem...

Be sure you specify the property as a function, not as a macro. It generally
means you type something like:

= FunctionName( )


in a property, with the = sign, and the ( ).




Vanderghast, Access MVP
 
So I copy all the information at the beginning and put it under the Option
Explicit portion, then just copy and edit the functions and call the
functions? I'll try this and see what happens. Thanks.

Kou
 
I did what I said, copied the data into a new Module named "FileDialog". I
then copied all the constants and declares at the top. I then tried a simple
function below and it didn't recognize the ahtAddFilterItem?

Public Sub Test()
Dim strFilter As String
Dim strSaveFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.xls")
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)

End Sub
 
The ahtAddFilterItem is probably in another module. You may use the Browser,
or the context menu over the name, ahtAddFilterItem, in the adh-mdb file, to
spot where it is defined, exactly (and you will have to copy that too).
That is why it may be preferable to add the whole mdb file as Reference
rather than copying a lot of (or all) modules (and classes).

If any name starting with the letters adh is missing, in your code, that
is probably because you need to copy something else, in the adh-mdb. They
use the prefix 'adh' just for that purpose: to signal you it is not
originally supplied by VBA.

That is why it may be preferable to add the whole mdb file as Reference
rather than copying a lot of (or all) modules (and classes).



Vanderghast, Access MVP
 
I assume you copy the code from an mdb, not from an article on the web. In
that case, it would be in the same mdb you use the portion of code you try
to run. The adh-mdb are 'complete' and do not need to use other mdb, so all
the required code should be present in the said mdb into which you spot the
code you want.


Vanderghast, Access MVP
 
Back
Top