Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 1st, 2003, 01:20 AM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default open a file in a form

Hi

I am creating a form that has a button. When the user clicks the button an open dialog box should appear letting the user choose a file. I know I have to create an event here using VB but I am not familiar with the command and the syntax.

Any ideas??

Thank you

Reply With Quote
  #2 (permalink)  
Old September 1st, 2003, 10:21 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: Houston, Texas, USA.
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use the common dialog or see the code below:

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

HTH,

Beth M
Reply With Quote
  #3 (permalink)  
Old September 1st, 2003, 10:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi J,

What version of Access are you using? What file type are you trying to open?

Invoking a file picker dialog has been greatly simplified in Access 2002 which includes a FileDialog property of the Application object. If you're using a version of Access prior to 2002, you'll need to use the Common Dialog ActiveX control that ships with the MOD edition of Office, an API call, or a custom class, none of which are trivial to implement.

Here's a sample of how you can use the FileDialog property in Access XP to select all files, or filter for just .mdb/.mde or .xls files from your current db:

Private Sub cmdFilePicker_Click()
    Dim varItem As Variant
    Dim strOut As String
    Const conFileDialogFilePicker As Long = 3

    With _
        Application.FileDialog(conFileDialogFilePicker)
        .ButtonName = "Select"
        .Title = "Choose your files"
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "All Files", "*.*", 1
        .Filters.Add "Access databases", "*.mdb; *.mde", 2
        .Filters.Add "Excel Files", "*.xls", 3
        .FilterIndex = 2
        .Show

        If .SelectedItems.Count > 0 Then
            For Each varItem In .SelectedItems
                strOut = strOut & varItem & vbCrLf
        Next varItem

        End If

    End With

    Me.txtSelectedFiles = strOut

End Sub

HTH,

Bob

Reply With Quote
  #4 (permalink)  
Old September 1st, 2003, 10:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi J,

While we're on the topic, here are some additional references I've found helpful in the past. Also, Ken Getz tackles this soluion using a custom file dialog class he wrote for the Access Developer's Handbook if you have a copy. The articles below hit the Common Dialog Control (which is the same .OCX (COMDLG32.OCX) used by Visual Basic, by the way) and the API call approach.

http://msdn.microsoft.com/library/de...ml/ima0201.asp
http://www.helenfeddema.com/access.htm (Coulmn #91)
http://support.microsoft.com/default...b;en-us;161286
http://support.microsoft.com/default...b;en-us;303066
http://msdn.microsoft.com/library/de...ml/ima1101.asp

Enjoy :)

Bob


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open one form or the other mean34dean Access VBA 4 August 21st, 2008 12:02 PM
Close all MdiChield form from open one form/Button salman .NET Framework 2.0 6 December 10th, 2007 03:21 AM
Close all MdiChield form from open one form salman .NET Framework 1.x 0 November 8th, 2007 12:32 AM
Open Form, run query, open form Grafixx01 Access 7 April 26th, 2007 11:32 AM
Open the "Open File" dialogue box piratelordx Access VBA 4 March 14th, 2006 10:08 PM



All times are GMT -4. The time now is 10:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.