Solved

Common Dialog in Access 2000

Posted on 2001-09-16
4
440 Views
Last Modified: 2008-02-01
I need to be able to browse for a file and insert that path into something. Is there something other than the common dialog control I can use? If not, (1) is the common dialog control on every system and (2) show me code to do this?
0
Comment
Question by:Misledman
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Paurths
ID: 6486137
hi Misledman,

the common dialog component does not always work when u distribute your application to another computer.
If u use API however, it will always work since it is part of windows itself.
Here u will find an example of that :
http://www.mvps.org/access/api/api0001.htm

cheers
Ricky
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 50 total points
ID: 6486470
Hi Misleadman,

Some other easy way to do this is using the COMDLG32.OCX ("Microsoft Common Dialog Control 6.0"):

In Access (Go to Module):

ACCESS Menu -> References -> Check "Microsoft Common Dialog Control 6.0"

IF Check "Microsoft Common Dialog Control 6.0" DOES NOT APPEAR..

Hit the Browse Button -> Navigate to x:\Windows\System -> find (or type in) COMDLG32.OCX -> Click
on Ok.

Then add the code like this:

'CD is the Common Dialog Control's name

CD.Flags = 4
CD.Filter = "Excel Files (*.xls)|*.xls"
CD.Open
If CD.FileName <> "" Then
      'A file is selected
      '...
End If

'You need to copy the COMDLG32.OCX and register it if your system don't get this file.

'Hope will help little.

0
 
LVL 2

Expert Comment

by:nschulz777
ID: 6504838
Post your email and Ill send you a sample mdb which uses windows API calls to browse for files. It avoids the headaches of some machines not having registered controls.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6504868
Hi Misledman,

Here is another sample that enable a user to launch whether Save or Open dialog:

Public Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Function OpenDialogBox(ByVal frm As Form, ByVal filter As String, ByVal title As String, ByVal OpenSave As Byte) As String
    Dim ofn As OPENFILENAME
    ofn.lStructSize = Len(ofn)
    ofn.hwndOwner = frm.hwnd
    ofn.hInstance = App.hInstance
    ofn.lpstrFilter = filter
    ofn.nFilterIndex = 1
    ofn.lpstrFile = Space$(254)
    ofn.nMaxFile = 255
    ofn.lpstrFileTitle = Space$(254)
    ofn.nMaxFileTitle = 255
    ofn.lpstrInitialDir = CurDir
    ofn.lpstrTitle = title
    ofn.flags = 6
    Dim OpenDialog As Long
    If OpenSave = 1 Then
        OpenDialog = GetOpenFileName(ofn)
        If (OpenDialog) Then
            If Dir$(Trim$(ofn.lpstrFile)) <> "" Then
                OpenDialogBox = Trim$(ofn.lpstrFile)
            End If
        Else
            OpenDialogBox = "" 'Cancel was pressed
        End If
    Else ' = 2
        OpenDialog = GetSaveFileName(ofn)
        If OpenDialog > 0 Then
            OpenDialogBox = Trim$(ofn.lpstrFile)
        Else
            OpenDialogBox = ""
        End If
    End If
End Function

'Hope will help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now