Browsing for a file - Please Help

G

Guest

I am trying to use the API found at
http://www.mvps.org/access/api/api0001.htm to allow a user to browse for a
file when they click the button.

I have created a form and created an event procedure. used code builder and
pasted a copy of this code beginning with the section that says "Code Starts
Here".

I am receiving the same error as mentioned in the thread by Greg M on
7/19/2005 -an error at the first declare statement and stating only comments
can follow an end sub or end function. The first declare statement follows
an end type.

Must I install this differently? Please see my other post today asking
about Microsoft Office Object 11.0 being used in other version of Access than
2003. I am trying to use this function across 2 versions of Access & Office.

Any help will be greatly appreciated.
 
G

Guest

Remove the last line:
'************** Code End *****************
I had the same problem when I copied it in to my system.

Excellent code, by the way.
 
D

Douglas J. Steele

Exactly where did you paste the code: into the existing module associated
with your form, or into another existing module, or into a brand new module?
It should be the last alternative. I don't believe it will work in a form
module. If you're pasting it into an existing module, the Declare statements
must be at the start of the file (after the Option Explicit, but before any
subs or functions)
 
D

Douglas J. Steele

Just for kicks, I copied it with the last line, and it worked fine for me.
 
G

Guest

It really should be in its own module. Interesting it worked without an
error for you. When I first copied it over, I put it in a new module and got
the same error she did. I deleted the last line '*********End of Code*****
and the problem went away.
 
G

Guest

Thanks to all of you for your quick and helpful replies. I do need to ask
for some additional assistance. I have done much work in Access with
queries, macros, etc., but am a novice at VBA code. Can you help me with
installing this API correctly. Once I copy this into a module, how do I call
it from a button or unbound control of a form?

Thanks
 
G

Guest

Here is an example where I use it:

'Set filter to show only Excel spreadsheets
strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)")
'Hides the Read Only Check Box on the Dialog box
lngFlags = ahtOFN_HIDEREADONLY

strCurrMonth = Me.cboPeriod.Column(1)
strCurrYear = Me.txtCurrYear
'Get the File Name To Save
strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" &
strCurrYear _
& " Actuals\" & strCurrMonth & "\"
varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear &
".xls"

varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _
strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _
"xls", varGetFileName, "Import Adjusted Actuals", , True)
Me.Repaint
If varGetFileName = "" Then 'User Clicked CANCEL
GoTo LoadAdjustedActuals_Exit
End If
 
G

Guest

Thanks so much for all your help. I also found Knowledge Database #303066
that gave some code that will browse for a file and place the selected
path/file name into a text box. This also gave instructions to install the
API. I used these same instructions to use Ken Getz's code and it works also
- but gives the file name in a dialog box.

You guys (don't take this as gender specific) are great!
 
C

CJG via AccessMonster.com

Hi Douglas,

I'm new to VB,so if this is a silly quesion...if I put this in a new module
and not a form module, how do I use it/get it to run when I need it?

Thanks,
CJG
Exactly where did you paste the code: into the existing module associated
with your form, or into another existing module, or into a brand new module?
It should be the last alternative. I don't believe it will work in a form
module. If you're pasting it into an existing module, the Declare statements
must be at the start of the file (after the Option Explicit, but before any
subs or functions)
I am trying to use the API found at
http://www.mvps.org/access/api/api0001.htm to allow a user to browse for a
[quoted text clipped - 20 lines]
Any help will be greatly appreciated.
 
D

Douglas J Steele

Putting it in a module exposes it so that you can use it anywhere, just like
any of the built-in functions (or at least it exposes any functions or subs
that aren't declared as Private)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


CJG via AccessMonster.com said:
Hi Douglas,

I'm new to VB,so if this is a silly quesion...if I put this in a new module
and not a form module, how do I use it/get it to run when I need it?

Thanks,
CJG
Exactly where did you paste the code: into the existing module associated
with your form, or into another existing module, or into a brand new module?
It should be the last alternative. I don't believe it will work in a form
module. If you're pasting it into an existing module, the Declare statements
must be at the start of the file (after the Option Explicit, but before any
subs or functions)
I am trying to use the API found at
http://www.mvps.org/access/api/api0001.htm to allow a user to browse
for a
[quoted text clipped - 20 lines]
Any help will be greatly appreciated.
 

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