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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to incorporate Browse into VBA application 2

Status
Not open for further replies.

KMITCH

MIS
May 1, 2000
42
US
Currently, whenever I need a filename and path from <br>the user in an Access 97 VBA app., I simply have them enter this into a message box.&nbsp;&nbsp;I then validate the path and filename and then make use of it in the code.<br><br>I would like to do this a little more professionally by having a browser pop up instead of a message box, so that the user can navigate to the needed file and not have to type it in.<br><br>Any help appreciated.<br><br>-Keith
 
I think that you can use Common Dialog control, you can add it using ActiveX controls and select (Microsoft COMMON DIALOG CONTROL).<br><br> <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
Thanks Mohamed.<br><br>I found the ActiveX you are referring to and inserted it into a form, though I'm not clear on how to take the next step to have it come up as a browser when the form runs.&nbsp;&nbsp;The help that comes with the ActiveX is not clear on this.&nbsp;&nbsp;The ActiveX seems to want a Filename and some other parameters, none of which I know what to enter for.<br><br>Thanks,<br>Keith
 
jimmythegeek posted and I found it to work perfectly.<br>Hope this helps! I know how aggrevating some of these tasks can be.<br><br>1) On your form, add a common dialog control (Insert ¦ ActiveX Control) (Microsoft common dialog control, version 5)<br>2) Name the control &quot;cdlgOpen&quot;<br>3) Add a button<br>4) Name the button &quot;cmdBrowse&quot;<br>5) Copy and paste the following code on the Click Event of the button (minus the Private & End Sub lines).<br><br>-----<br>Private Sub cmdBrowse_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim strFile As String<br>&nbsp;&nbsp;&nbsp;&nbsp;With Me.cdlgOpen<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.CancelError = True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Filter = &quot;Excel Files (*.xls)¦*.xls¦&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ShowOpen<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strFile = .filename<br>&nbsp;&nbsp;&nbsp;&nbsp;End With<br>End Sub<br>-----<br><br>6) Now your variable strFile will represent your file and you can do with it as you wish from that point.<br><br>
 
Thanks hcsd.&nbsp;&nbsp;This works great.<br><br>-Keith
 
Glad to be of assistance but I can't take credit for this one.<br>Thanks to &quot;jimmythegeek.&quot;<br><br>Steve
 
Sorry to be such a novice, but:

There was no comdlg32.ocx file on my win95b system, so I downloaded one. Then used Access->Tools->ActiveX Controls menu to &quot;register&quot; it.

Then when I did the instruction:

1) On your form, add a common dialog control (Insert ¦ ActiveX Control) (Microsoft common dialog control, version 5)

I got a message: &quot;You don't have the license required to use this ActiveX control&quot;.

Also, on another machine, the message was &quot;The OLE server isn't registered.&quot;

So am I stuck? If so, is there another solution to the browse problem?

Thanks,
Dave
 
Hi!

You may also find GetOpenFilename useful, example:

Private Sub CommandButton1_Click()
ChDrive Left(DataFolder, 2)
ChDir DataFolder &amp; &quot;\MeasData&quot;
DataFileName = Application.GetOpenFilename _
(&quot;Data files (*.dat), *.dat&quot;, 1, &quot;DATA&quot;)
If DataFileName = False Then Exit Sub
'open and read the file or whatever
'...
End Sub

/best regards, HGB
 
To hcsd:
When I pull up the &quot;About Access&quot; screen it says Microsoft Access 97 on the top line and then SR-1 right below that.

To HGB:
I didn't think GetOpenFilename was available in Access 97

Thanks,
Dave
 
Hello;

When I've tried any of the ActiveX controls mentioned so far, I keep running into the license wall. I'm curious as to whether people who have used these controls found a way around this problem or have received a license from some other source. For example, at work I use MSCOMCTL.ocx in an Access application but the license for it derives from standalone Visual Basic. Also I know that the developer's edition of Access comes with a version of this control.

By the way, in Access97 there is an undocumented function inside of Access which will put up a file browse dialog. If interested I can post the code required.

Sincerely,
Chell (chell@blarg.net)
 
Thanks Chell! The Access Developer's Handbook code you sent me works like a charm! :) I stripped it down to just the file browse stuff, but I agree that it's still probably too big to post here. If anyone ever wants my modified version, email me at dave@dancingpeace.com
-Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top