Browse button

M

maria

I will like to create a browse button than open the directory C:\ and after I
select the file it put the path in a text box which is a hyperlink.
I read a load of question already posted because I don’t want to repeat a
question.

I download these one;
http://community.compuserve.com/n/p...yMessages&tsn=1&tid=22415&webtag=ws-msdevapps
but I am having some trouble with it since I am not familiar with VBA
procedures, I am just copy/paste the procedure.

I follow all the instruction. I save the Class Module
BrowseForFileClass.txt. The form has a browse button name=â€BrowseBtn†and a
textbox name=â€FormLetterCboâ€

When I click on the browse button I receive this message:
“Compaile error
User-defined type not defineâ€.

After click on OK it take me to the VBA screen and select “OpnDialog As New
BrowseForFileClass “

Where I should define the OpnDialog or what I am doing wrong?

I also try these one: http://www.mvps.org/access/api/api0001.htm; but after
I copy the prodedure I receive the message:
“The expression on click you entered as the event property setting prodece
the following error: Only comment may appear after End Sub, End Function, or
End Property.


Appreciate some help.
Thanks in advanced.
 
D

Daniel

Maria,

Ref: http://www.mvps.org/access/api/api0001.htm

you obviously copied text that isn't part of the code and thus is genearting
the error. Make sure to copy only what is between the code start and code
end and paste them into a new module. Then perform a compile to check for
problems before going any further.

Then on your form create a new button and add

call Testit

save your form and open it normally and click on your button to see if it is
working! it should.

now, it is just a question of copying the code in the Testit function ad
pasting in in your event procedure for your button and customizing it for
exactly your needs by adjusting the

strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

to suit your needs. Each of the strFilter above will display different file
types.you can comment out those that you do not need by adding a ' in front
on the line (it will then become green). You can also create your own filter
by changing the "*.extension") to whatever you are looking for. Such as

strFilter = ahtAddFilterItem(strFilter, "Word Documents (*.doc)", "*.doc")

Hope this helps, Let me know if something is still not clear.

Daniel
 
K

Ken Sheridan

To judge by your post I think where you've gone wrong with Bill Wilson's
BrowseForFileClass is naming the class module BrowseForFileClass.txt; it
should be named simply BrowseForFileClass without the extension. So change
the name of the class module first, then for the button's Click event
procedure use:

Private Sub BrowseBtn_Click()

On Error GoTo Err_Handler

Dim OpenDlg As New BrowseForFileClass
Dim strPath As String

OpenDlg.InitialDir = "C:\"
OpenDlg.DialogTitle = "Select File"
strPath = OpenDlg.GetFileSpec
Set OpenDlg = Nothing

If Len(strPath) > 0 Then
Me.FormLetterCbo = strPath
End If

Exit_Here:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here

End Sub

where txtLink is the name of the text box. For the text box's Click event
procedure put the following to open the file in a new window:

Private Sub FormLetterCbo_Click()

On Error GoTo Err_Handler

FollowHyperlink Me.txtLink, , True

Exit_Here:
Exit Sub

Err_Handler:
MsgBox "Unable to open file.", vbExclamation, "Error"
Resume Exit_Here

End Sub

Ken Sheridan
Stafford, England
 
M

maria

I use Bill Wilson's procedure, and follow the instructions that Ken sent in
the last post.

It works OK, Thanks Ken and Daniel!
 

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