Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2003, 01:20 AM
Registered User
 
Join Date: Aug 2003
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

 
Old September 1st, 2003, 10:21 AM
Friend of Wrox
 
Join Date: Jul 2003
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
 
Old September 1st, 2003, 10:25 AM
Friend of Wrox
 
Join Date: Jun 2003
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

 
Old September 1st, 2003, 10:45 AM
Friend of Wrox
 
Join Date: Jun 2003
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







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





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