Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Microsoft: Access Other topics FAQ

Access Howto:

How do I use a Browse button to Open and Save files?
Posted: 21 Jul 00 (Edited 27 Sep 07)

This example uses the Microsoft ActiveX control. The Access Developers handbook has another example.

1) On your form, add a common dialog control
   (Insert | ActiveX Control) (Microsoft common dialog control, version 5)
2) Name the control "cdlgOpen"
3) Add a button
4) Name the button "cmdBrowse"
5) Optional: I use either a private or public constant for my default path if you want one.

In General Declaration Section of form (private) or module (public):

Private Const EXISTINGFILE As String = "C:\My Documents\Zips\tasks.xls"
Private Const EXISTINGDIR AS String = "C:\MyDocuments\"

5) Copy and paste the following code on the Click Event of the button (minus the Private & End Sub lines).

==========
Private Sub cmdBrowse_Click()
   Dim strNewFile As String
                           
   On Error GoTo Browse_Err
   With Me.cdlgOpen
      'You should only use one of the next two lines if you want to open to either a default file or folder
      .filename = EXISTINGFILE  'Comment out if you don't want to open to a default file
      '.initdir = ESIXTINGDIR  'Comment out if you don't want to open to a default folder
      .CancelError = True
      .Filter = "Excel Files (*.xls)|*.xls|"   'Can change (i.e. "Word Files (*.doc)|*.doc|") or ("All Files (*.*)|*.*|") see help for other examples
      .ShowOpen   ' Can use showSave for saving file, same principle
      strNewFile = .filename
   End With
                             
Browse_Exit:
   Exit Sub

Browse_Err:
   If Err.Number = 32755 Then
      Resume Browse_Exit
   Else
      MsgBox Err.Number & ": " & Err.Description
      Resume Browse_Exit
   End If
End Sub
==========

6) Now your variable strFile will represent your file and you can do whatever you want with it at that point.

If your default paths have the possibility of changing, you might consider putting them into a table or .ini file and retrieving them. This will allow you to change the path without having to adjust your code.

==========================

Jim Lunde
jimlunde@gmail.com

Back to Microsoft: Access Other topics FAQ Index
Back to Microsoft: Access Other topics Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close