Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just want a Simple Browser Button

Status
Not open for further replies.

jprochelle

Technical User
Jun 18, 2004
36
0
0
US
someone please help! All I am trying to do is create a simple browser button that will search through directories and return the filepath in a textbox called "txtFilePath". I've searched high and low through the forums- but all these are either too complex or just don't work for my form. I don't want to save or open any files- just merely place the file path in the textbox.

Thanks!
 
Take a look at the FileDialog object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm a little concerned about what you consider "too complex." Searching all directories and subdirectories for a specific file will most likely require some sort of recursive process, and there are several approaches that you can take.

Perhaps you can share one or two of the alternatives that you've found, but are too complex so that we can get a better understanding of proper level of complexity that you're comfortable with.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
One user suggested I use this coding:
Dim fname As FileDialog
Dim itm As Object
Set fname = Application.FileDialog(msoFileDialogOpen)

With fname
.AllowMultiSelect = False
.Show
End With

With fname
For Each itm In .SelectedItems
Me.txtFilePath = itm
Next
End With


But, not only does an error msg arise saying "doesn't recongize outside source"..for the SET function- but I'm not sure what to put in the command button's event procedure.

 
jp,

Make sure the Microsoft Office Object Library is checked in the references.

Inside the code window, click Tools>References to see what references you have. If you do not have it checked, the File Dialog box will not work properly.

Robotron
 
this ALMOST works great-- except when I do it, an error msg comes up saying Run time error 424. Then, it highlights the 2nd line of this code:

With fname
----> For Each itm In .SelectedItems
Me.txtFilePath = itm

I guess it's not recognizing .SelectedItems??? When I click the "browse" command button, the directory opens...but then when i click the file name- it doesn't populate in either the directory filepath box or my text box.
 
jp, Try this:

Code:
    With fname
        .AllowMultiSelect = False
        If .Show = True Then    
            For Each itm In .SelectedItems
                Me.txtFilePath = itm
            Next
        End if
    End With

Robotron
 
I'm using this exact code and the same error occurs.

Private Sub Command8_Click()
Dim fname As FileDialog
Dim itm As Object
Set fname = Application.FileDialog(msoFileDialogOpen)
With fname
.AllowMultiSelect = False
If .Show = True Then
For Each itm In .SelectedItems <--ERROR is here
Me.txtFilePath = itm
Next
End If
End With
End Sub
 
Try declaring itm as variant in stead of object.

Roy-Vidar
 
jp,

Change

Dim itm as Object

to

Dim itm as Variant

Robotron
 
Hi jprochelle,

I hope you are still listening to this thread......

I am trying to achieve the same results as you have here but I get an error saying that FileDialog is a User defined type that is not defined...... Do you know what reference is associated to it? Where am I going wrong?

Thanks,

Simon
 
Hi Spandex,

The answer is already in the thread;

Make sure the Microsoft Office Object Library is checked in the references.

Inside the code window, click Tools>References to see what references you have. If you do not have it checked, the File Dialog box will not work properly.

Robotron

I think thats what you need.

Sim


----------------------------------------
I was once asked if I was ignorant or just apathetic. I said, "I don't know, and I don't care."
----------------------------------------
 
Hi Sim,

Well there lies the problem. I am using Access 2000 and so I have found out to my dismay, FileDialog isn't available... I have been trying to find a solution in 2000 but they don't seem too easy... I'm a bit of a novice...

thread181-452408 looks like it is on the right track but I keep getting errors....
 
Ah,

hmmm, I seem to recall this conversation happening before and I got it wrong there too :D

thread181-47689 Take a look here and see if that helps.

Simon

----------------------------------------
I was once asked if I was ignorant or just apathetic. I said, "I don't know, and I don't care."
----------------------------------------
 
Thanks Simon,

I have just managed to get another option to work and so far it is going well!

Cheers,

Simon
 
Actually while I have your attention Spandex, could you give Mike Lacey a poke as I have had an application for access to the UKTT forum for weeks (Put it on the day before the update on the site style)

Any help would be appreciated :)

Ta fanks
Sim

----------------------------------------
I was once asked if I was ignorant or just apathetic. I said, "I don't know, and I don't care."
----------------------------------------
 
I'm back with news Simon!

Spoke to Mike, the part of the site that lets him add new users is still down. He says as soon as it is up he will go through his list of new applicants.

So hopefully I will see you in the TTUK lounge soon!

All the best,

Simon

"A picture is not worth a 1000 words on the Internet. The information is in the text."
 
Good answer, and it helped me a lot, once I figured out that the field txtFilePath has to be an OLE type, and not a text field.

If this was utterly obvious to everyone else, sorry.

Brendan

"catch-phrases are just soooooooo last year
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top