Link to home
Start Free TrialLog in
Avatar of Misledman
MisledmanFlag for United States of America

asked on

Common Dialog in Access 2000

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?
Avatar of Paurths
Paurths

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
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.